VC++ (VS2008)里面char和LPTSTR的转换问题
2011-07-21 09:28
441 查看
在VS里面写如下代码,实现两个数的相加并且显示结果:
原因是字符集的问题。VS2008和VC6.0还是有些不一样的。
参考资料:http://topic.csdn.net/u/20090506/17/d7e4b312-ba8a-4611-b94b-59c5c7a96aea.html
解决方案:
char 改成TCHAR
atoi 改成 _ttoi
itoa 改成 _itot
int num1,num2,num3; char ch1[10],ch2[10],ch3[10]; GetDlgItem(IDC_EDIT1)->GetWindowText(ch1,10); GetDlgItem(IDC_EDIT2)->GetWindowText(ch2,10); num1=atoi(ch1); num2=atoi(ch2); num3=num1+num2; itoa(num3,ch3,10); GetDlgItem(IDC_EDIT3)->SetWindowText(ch3);编译运行出现错误:
1>.\TestDlg.cpp(42) : error C2664: “int CWnd::GetWindowTextW(LPTSTR,int) const”: 不能将参数 1 从“char [10]”转换为“LPTSTR” 1> 与指向的类型无关;转换要求 reinterpret_cast、C 样式转换或函数样式转换 1>.\TestDlg.cpp(43) : error C2664: “int CWnd::GetWindowTextW(LPTSTR,int) const”: 不能将参数 1 从“char [10]”转换为“LPTSTR” 1> 与指向的类型无关;转换要求 reinterpret_cast、C 样式转换或函数样式转换 1>.\TestDlg.cpp(53) : error C2664: “CWnd::SetWindowTextW”: 不能将参数 1 从“char [10]”转换为“LPCTSTR” 1> 与指向的类型无关;转换要求 reinterpret_cast、C 样式转换或函数样式转换
原因是字符集的问题。VS2008和VC6.0还是有些不一样的。
参考资料:http://topic.csdn.net/u/20090506/17/d7e4b312-ba8a-4611-b94b-59c5c7a96aea.html
解决方案:
char 改成TCHAR
atoi 改成 _ttoi
itoa 改成 _itot
TCHAR ch1[10],ch2[10],ch3[10]; GetDlgItem(IDC_EDIT1)->GetWindowText((ch1),10); GetDlgItem(IDC_EDIT2)->GetWindowText((ch2),10); num1=_ttoi(ch1); num2=_ttoi(ch2); num3=num1+num2; _itot(num3,ch3,10); GetDlgItem(IDC_EDIT3)->SetWindowText(ch3);
相关文章推荐
- VC++ (VS2008)里面char和LPTSTR的转换问题
- VC++ (VS2013)里面char和LPTSTR的转换问题
- VS2008 不能将参数从“LPCTSTR”转换为“const char*”问题
- char*数组(c类型字符串)和Vc++中的CString的转换,char*数组等问题
- 我把一个VC6的工程转换为VS2008的工程后,编译总是出现找不到而且不能升级vc90.pdb文件的问题,error C2471--解决办法
- VC++的小问题:const char[]无法转换到LPCWSTR
- VS2008MFC中CString转换成char数组的问题
- C++: VC6转VC8出现问题:error C2664: “fopen”: 不能将参数 1 从“CString”转换为“const char *” from http://www.cnblogs.com/moon2bird/archive/2009/02/27/1399675.html
- VS2008下,CString与string互转换,LPTSTR转CString,char * 转LPTSTR
- 我把一个VC6的工程转换为VS2008的工程后,编译总是出现找不到而且不能升级vc90.pdb文件的问题,error C2471--解决办法 2010-9-16 15:01
- VS2008和VC之间变量的转换问题
- C++: VC6转VC8出现问题:error C2664: “fopen”: 不能将参数 1 从“CString”转换为“const char *”
- C++: VC6转VC8出现问题:error C2664: “fopen”: 不能将参数 1 从“CString”转换为“const char *”
- 一个VC6的工程转换为VS2008的工程后,编译找不到而且不能升级vc90.pdb文件的问题解决方法 2010-9-28 14:00
- 【VC++】不能将参数 1 从“_TCHAR”转换为“const char* 问题解决
- VS2008环境中LPCWSTR类型转换问题解决方法
- delphi pchar char byte string转换问题
- MFC中CString转换成char数组的问题
- CString转换成char *字符串问题
- 移植性问题のLPTSTR、LPCSTR、LPCTSTR、LPSTR之间的转换 转