请问在mfc中,怎么把一个CString类型的字符写进.txt文件中?

我是直接用ofstream fout;
fout.open("DrugInfo.txt");
fout<<...;
结果在文件中显示的貌似是CString这个变量的地址,求解怎么把汉字字符输入文件里面啊

CString变量用LPCTSTR等转换一下,再写入文件

CString str = "123";
CStdioFile File;  
File.Open(_T("DrugInfo.txt"), CFile::modeReadWrite|CFile::modeNoTruncate|CFile::modeCreate); 
File.WriteString(str);

标签错啦。。是CString不是cstring ,mfc里面的啊

CString abc("abc123");
ofstream ofs("D:\a.txt");
if (!ofs.bad())
{
ofs.seekp(0,ios::end);
ofs<< abc.GetBuffer(0);
ofs.seekp(0,ios::end);
ofs<< abc.GetBuffer(0);
ofs.close();
}

我把项目属性从UNICODE字符集改成多字符字符集就能正常添加了,不过界面风格变了,这是怎么一回事啊

系统是用的多字符集的系统吗?
字符集影响字符的二进制储存方式,我估计你的程序和系统使用的字符集不同。这样输出到TXT会出现乱码。

使用LPCTSTR将CString变量做转换,然后写入.TXT文件!

CString temp = _T("ABCDE");
CFile fp;
fp.Open( m_strExtPath, CFile::modeWrite|CFile::modeCreate );
fp.Write( temp.GetBuffer() , temp.GetLength() );
fp.Close();

标签错啦。。是CString不是cstring ,mfc里面的