MFC string CString char wchar 相互转换

实在太多也太难整理,只能遇到一次补一个,网上很多都是错的,先把遇到的写出来,慢慢更新......


// wcharTochar 
void wcharTochar(const wchar_t *wchar, char *chr, int length)
{
	WideCharToMultiByte(CP_ACP, 0, wchar, -1,
		chr, length, NULL, NULL);
}
wchar_t buf[100];
char str[100];
wcharTochar(buf,str, sizeof(str));

//char TO string 
char str[100];
CString ss(str);


1. CString 转int long double   
  
CString str = "";  
double x = _wtof(str);  
int x = _wtoi(str);  
long x = _wtol(str);  
  
atoi atof 这些函数会报错  
因为参数要是( const char* )  
  
2. int ,double ,long 转CString  
str.Format(_T("%.4d"),x);  


你可能感兴趣的:(windows,编程)