今天看啥
热点:

一点经验。在VC2005编程环境中,要有UNICODE意识。一般安全的做法是用TCHAR代替char使用,为字符串赋值时,用_T(" ")代替" "。因为在tchar.h中有如下声明:

#ifdef _UNICODE
typedef wchar_t     TCHAR;
#define __T(x)      L##x
#define _T(x)       __T(x)
#else
#define __T(x)      x
typedef char            TCHAR;
#endif

T(_T宏)表示兼容ANSI和Unicode

\


If you are using Unicode or MBCS then you need to be careful when writing ASCII files. The safest and easiest way to write text files is to use the CStdioFile class provided with MFC. Just use the CString class and the ReadString and WriteString member functions and nothing should go wrong. However, if you need to use the CFile class and its associated Read and Write functions, then if you use the following code:

CFile file(...);
CString str = _T("This is some text");
file.Write( str, (str.GetLength()+1) * sizeof( TCHAR ) );
instead of

CStdioFile file(...);
CString str = _T("This is some text");
file.WriteString(str);
then the results will be Significantly different. The two lines of text below are from a file created using the first and second code snippets respectively:


但是在使用CStdioFile::WriteString(str)时,若str包含亚洲字体如中文、日语等(在 Unicode 环境下),这些字体确显示不出来,现在我也没找到解决的办法,不知哪位知道告诉我一声,另:
Be careful when performing operations that depend on the size or length of a string. For instance, CString::GetLength returns the number of characters in a string, NOT the size in bytes. If you were to write the string to a CArchive object, then you would need to multiply the length of the string by the size of each character in the string to get the number of bytes to write:

CString str = _T("Hello, World");
archive.Write( str, str.GetLength( ) * sizeof( TCHAR ) );

CFile对象的Write也一样。

www.bkjia.comtruehttp://www.bkjia.com/VCjc/522123.htmlTechArticle一点经验。在VC2005编程环境中,要有UNICODE意识。一般安全的做法是用TCHAR代替char使用,为字符串赋值时,用_T(" ")代替" "。因为在tchar.h中有...

相关文章

    暂无相关文章
相关搜索:

帮客评论

视觉看点