cstring

MFC常用类

流过昼夜 提交于 2019-11-26 14:57:45
CString CStringT 操作可变长度字符串的模板类CStringT有三个实例: CString、CStringA和CStringW ,它们分别提供对TCHAR、char和wchar_t字符类型的字符串的操作。 char类型定义的是Ansi字符,wchar_t类型定义的是Unicode字符,而TCHAR取决于MFC工程的属性对话框中的Configuration Properties->General->Character Set属性,如果此属性为Use Multi-Byte Character Set,则TCHAR类型定义的是Ansi字符,而如果为Use Unicode Character Set,则TCHAR类型定义的是Unicode字符。 构造函数 CString(const CString& stringSrc);//将一个已经存在的CString对象stringSrc的内容拷贝到该CString对象。 CString(LPCTSTR lpch, int nLength);//将字符串lpch中的前nLength个字符拷贝到该CString对象。 CString(TCHAR ch, int nLength = 1);//使用此函数构造的CString对象中将含有nLength个重复的ch字符。 转换函数 CString& MakeLower(); /

How is std::string implemented?

只谈情不闲聊 提交于 2019-11-26 11:15:52
I am curious to know how std::string is implemented and how does it differ from c string?If the standard does not specify any implementation then any implementation with explanation would be great with how it satisfies the string requirement given by standard? Michael Burr Virtually every compiler I've used provides source code for the runtime - so whether you're using GCC or MSVC or whatever, you have the capability to look at the implementation. However, a large part or all of std::string will be implemented as template code, which can make for very difficult reading. Scott Meyer's book,

How to convert CString and ::std::string ::std::wstring to each other?

泪湿孤枕 提交于 2019-11-26 08:48:48
问题 CString is quite handy, while std::string is more compatible with STL container. I am using hash_map . However, hash_map does not support CString as key, so I want to convert CString into std::string . Writing a CString hash function seems to take a lot of time. CString -----> std::string How can I do this? std::string -----> CString: inline CString toCString(std::string const& str) { return CString(str.c_str()); } Am I right? EDIT: Here are more questions: How can I convert wstring , CString

What is std::string::c_str() lifetime?

泪湿孤枕 提交于 2019-11-26 00:48:14
问题 In one of my programs, I have to interface with some legacy code that works with const char* . Lets say I have a structure which looks like: struct Foo { const char* server; const char* name; }; My higher-level application only deals with std::string , so I thought of using std::string::c_str() to get back const char* pointers. But what is the lifetime of c_str() ? Can I do something like this without facing undefined behavior ? { std::string server = \"my_server\"; std::string name = \"my

【转】Cstring 使用说明

扶醉桌前 提交于 2019-11-25 22:12:12
1.CString::IsEmpty BOOL IsEmpty( ) const; 返回值:如果CString 对象的长度为0,则返回非零值;否则返回0。 说明:此成员函数用来测试一个CString 对象是否是空的。 示例: 下面的例子说明了如何使用CString::IsEmpty。 // CString::IsEmpty 示例 CString s; ASSERT( s.IsEmpty() ); 请参阅 CString::GetLength 2.CString::Left CString Left( int nCount ) const; throw( CMemoryException ); 返回值:返回的字符串是前nCount个字符。 示例: CString s( _T("abcdef") ); ASSERT( s.Left(2) == _T("ab") ); 3.CString::LoadString BOOL LoadString( UINT nID ); throw( CMemoryException ); 返回值:如果加载资源成功则返回非零值;否则返回0。 nID 一个Windows 字符串资源ID。 说明: 此成员函数用来读取一个由nID 标识的Windows 字符串资源,并放入一个已有CString 对象中。 示例: 下面的例子说明了如何使用CString: