+ -
当前位置:首页 → 问答吧 → MFC输出到txt问题

MFC输出到txt问题

时间:2011-12-02

来源:互联网

本人基本小白一只,下周二要交的大作业,求各位大神帮忙~
要求是基于对话框编写一个通讯录程序。之前有做过控制台的,用的是i/o流输入输出,但是把原来的string改成CString了之后输出的都是乱码。
ofstream outfile ("AddressBook.txt",ios::out|ios::app);//打开文件
outfile<<name<<" "<<birthYear<<" "<<birthMonth<<" "<<birthDay<<" "<<telnumber<<" "<<email<<'\n';
//name,telnumber,email,为cstring型,birthYear,birthMonth,birthDay,为int型

作者: mummymyth   发布时间: 2011-12-02

你是不是编译的时候 的 字符集 是 unicode的 ??

作者: dhbfly   发布时间: 2011-12-02

那你就把CString转为string

你挑着用:

CString strSrc("123");

CStringA strSrcA(strSrc);
CStringW strSrcW(strSrc);

const char* p1 = strSrcA;
const WCHAR* p2 = strSrcW;

string strDesA((LPCSTR)strSrcA);
wstring strDesW((LPCWSTR)strSrcW);

作者: lgstudyvc   发布时间: 2011-12-02

引用 1 楼 dhbfly 的回复:

你是不是编译的时候 的 字符集 是 unicode的 ??

我在项目属性里改成了多字节字符集,再试还是乱码

作者: mummymyth   发布时间: 2011-12-02

引用 2 楼 lgstudyvc 的回复:

那你就把CString转为string

你挑着用:

CString strSrc("123");

CStringA strSrcA(strSrc);
CStringW strSrcW(strSrc);

const char* p1 = strSrcA;
const WCHAR* p2 = strSrcW;

string strDesA((LPCSTR)strSr……

转成string也还是乱码

作者: mummymyth   发布时间: 2011-12-02