ifstream in(_T("EastCompensation.txt"));
string s;
while(getline(in,s));
in.close();
CString cstr;
cstr.Format(_T("%s"),s);
MessageBox(cstr);
string s;
while(getline(in,s));
in.close();
CString cstr;
cstr.Format(_T("%s"),s);
MessageBox(cstr);
第二:Format之类的函数应该不可以使用string作为参数,他只支持简单类型,如果你要用Format,s需要改成s.c_str()
->cstr.Format(_T("%s"),s.c_str());
123456
-456945
789654
……
MessageBox依然是乱码
string s;
if(in.getline((char *)s.c_str(),15))
{
CString cstr;
cstr=s.c_str();
MessageBox(cstr);
in.close();
}
else
MessageBox(_T("open failed!"));
这样试了一下,居然可以了,虽然不知道原因。说明一下我的运行平台是vs2008模拟器windows mobile 5.0 packet pc
cstr.Format(_T("%s"),s);
->cstr.Format(_T("%s"),s.c_str());
重点是字符宽度,要搞清楚。