把CString写入string之后,为什么变成乱码了呢? you should follow this:CString cstr = "12 hehe";stringstream ss;int n;ss << (const char*)cstr;ss >>n; 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 要把CString 里的字符先取出GetBufferCString cstr = "12 hehe";stringstream ss;int n;ss << cstr.GetBuffer();ss >>n; hurryboylqs的方法得到:error C2440: 'type cast' : cannot convert from 'CString' to 'const char *'gaijiaofan() 的方法得到:n仍然不是我想要的数字,StringBuffer依然乱七八糟。 To lz: 你是不是使用的UNICODE编码?如果是,那么就请用下面的方式代替:// VC6: 没有CStringW// CString 就是 CStringTCString cstr = L"12 hehe";wstringstream ss;int n;ss << L"12 hehe";ss >>n;// 若为VC7,可以显式使用CStringWCStringW cstr = L"12 hehe";wstringstream ss;int n;ss << L"12 hehe";ss >>n; Sorry 更正一下:// 若为VC7,可以显式使用CStringWCStringW cstr = L"12 hehe";wstringstream ss;int n;ss << (LPCWSTR)cstr;ss >>n; 后来用了这个:ss << CW2A(cstr); 就好用了 my good,unicode那你就转换一下贝,自己本身都用的不是unicode字符当然有问题啦,VC6以后的版本要注意unicode转化,因为它默认的编译方式是unicode,最好用微软提供的转换宏比如_T(x),TEXT(x) VC代码着色器,不要老罗的,也不要C2的 关于CoCreateInstance的问题 简单问题,但是我不会 真的没有人会吗?如何手动使得某一个菜单项的某一个子项变灰(失去功能),或者隐藏? 请教:在sdk,关于子窗口过程控制的问题? 如何读取一个按纽上显示的值 问个静态文本框的问题 MDI中,怎样在MyAppDoc()中获得MyAppView()里的pDC????? 用PostMessage传递消息,如何将包含CArray的结构作为参数传递 ? win2000上的新的进程优先级在哪里? 连接问题 在win32 console 下怎么保存文件
GetBuffer
CString cstr = "12 hehe";
stringstream ss;
int n;
ss << cstr.GetBuffer();
ss >>n;
error C2440: 'type cast' : cannot convert from 'CString' to 'const char *'gaijiaofan() 的方法得到:n仍然不是我想要的数字,StringBuffer依然乱七八糟。
你是不是使用的UNICODE编码?
如果是,那么就请用下面的方式代替:// VC6: 没有CStringW
// CString 就是 CStringT
CString cstr = L"12 hehe";
wstringstream ss;
int n;
ss << L"12 hehe";
ss >>n;
// 若为VC7,可以显式使用CStringW
CStringW cstr = L"12 hehe";
wstringstream ss;
int n;
ss << L"12 hehe";
ss >>n;
CStringW cstr = L"12 hehe";
wstringstream ss;
int n;
ss << (LPCWSTR)cstr;
ss >>n;
比如_T(x),TEXT(x)