前提:MFC中才有CString 而標準C++中只有string
1.標準C++ 其他類型 轉string:
int x = 0;
string str =to_string(x);
string轉其他: 利用stringstream
float str2float(string num)
{
float res;
stringstream stream(num);
stream>>res;
return res;
}
2。對於unicode編碼來說,CString 轉其他類型可以用_ttof _ttoi 等
_tstof
float x;
3.對於ansi來說,使用atoi atof 由CString轉其他類型
下面文章中對於mfc不能使用atof問題做了講解
https://blog.csdn.net/lhw19931201/article/details/90178499
我的工程使用的是unicode 字符集,而atof是ansi定義的。