游戏开发论坛

 找回密码
 立即注册
搜索
查看: 1723|回复: 2

string的用法是什么

[复制链接]

97

主题

590

帖子

590

积分

高级会员

Rank: 4

积分
590
QQ
发表于 2004-7-7 20:03:00 | 显示全部楼层 |阅读模式
想定义字符串数组,用指针只能定义一个字符串。没数组方便,但STRING的用法不太清楚,请指教。

37

主题

180

帖子

180

积分

注册会员

Rank: 2

积分
180
发表于 2004-7-7 22:00:00 | 显示全部楼层

Re: string的用法是什么

自己包一个比较快

///////////////////////////////////////////////////////////////////////////////
//        Class Declaration
///////////////////////////////////////////////////////////////////////////////
/**
*        @class        DiString
*
*        @brief        A class that is very similar to CString
*
*        @usage
*/
class DiString
{
public:
        ////////////////////////////////////////////////////////////////////////////
        // C O N T R U C T O R S / D E S T R U C T O R S
        ////////////////////////////////////////////////////////////////////////////
        //! Constructor
        DiString(void);
        //! Constructor
        DiString( const DiString& other );
        //! Constructor
        DiString( LPCTSTR pszText, UINT uintBufferLength = 0 );
        //! Destructor
        ~DiString(void);

        ////////////////////////////////////////////////////////////////////////////
        // P U B L I C   M E T H O D S  -  O P E R A T I O N S
        ////////////////////////////////////////////////////////////////////////////
        //!--------------------------------------------
        //! Operator
        //!--------------------------------------------
        //!        是否为空字串
        bool        IsEmpty(void);
        //! Get the length of current text
        UINT        GetLength(void)                                        { return GetData()->m_dwTextLength; }
        //! Get pointer to buffer for direct modification
        LPTSTR        GetBuffer( UINT dwLength );
        //!        释放buffer
        void        ReleaseBuffer(void);
        //!        添加文字 ( += )
        void        Add( LPCTSTR pszText );
        //!        寻找文字
        int                Find( LPCTSTR pszString, UINT uintCount = 0 );
        //! 比对文字
        int                Compare( LPCTSTR pszText )        const        { return _tcscmp( m_pszText, pszText ); }
        //!        转换字串
        void        Format(LPCSTR str, ...);
        //!
        bool        LoadResource( HINSTANCE hInst,  UINT ResID, UINT dwLength = 0xff );
        //!        是否 float
        bool        IsFloat(void);
        //!        转换 float
        //float        ToFloat(void);
        //! 转换 float
        int                ToInt(void);
.....

18

主题

573

帖子

573

积分

高级会员

Rank: 4

积分
573
发表于 2004-7-8 14:14:00 | 显示全部楼层

Re:string的用法是什么

用vector和string结合。
vector<string> str;
str.push_back("str1");
str.push_back("str2");
……
使用时
str[0],str[1],……str[n]
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

作品发布|文章投稿|广告合作|关于本站|游戏开发论坛 ( 闽ICP备17032699号-3 )

GMT+8, 2025-7-3 11:19

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表