本帖最后由 piazini 于 2022-6-2 16:52 编辑
问题已解决,感谢大家都热心帮助。
解决方法:
VC60本来就是窄字符,所以不用转换,教程的里的目的也是把宽字符转换到窄字符
详见 24# (24楼回答)
-----------------------------------------------------------------------------------
按网上说的,下面这个两个都没用,编译还是报错。请教各位大佬怎么解决?
方法一:要加#include <afx.h>文件
方法二:要改project->settings->general->microsoft foundation classes->选use MFC in a static library
或选 use MFC in a shared DLL(需要把MFC的动态库放在system32文件夹下)
问题截图:
代码:
[C++] 纯文本查看 复制代码 CString name,pwd;
//CString 转char *
CStringA tmp;
CStringA tmp2;
file.ReadLogin(name,pwd);
tmp = name;
tmp2 = m_surePwd;
file.WritePwd( tmp.GetBuffer(), tmp2.GetBuffer() );
错误提示:
D:\mfc-heima-3day\SaleSystem\UserDlg.cpp(111) : error C2065: 'CStringA' : undeclared identifier
D:\mfc-heima-3day\SaleSystem\UserDlg.cpp(111) : error C2146: syntax error : missing ';' before identifier 'tmp'
D:\mfc-heima-3day\SaleSystem\UserDlg.cpp(111) : error C2065: 'tmp' : undeclared identifier
D:\mfc-heima-3day\SaleSystem\UserDlg.cpp(112) : error C2146: syntax error : missing ';' before identifier 'tmp2'
D:\mfc-heima-3day\SaleSystem\UserDlg.cpp(112) : error C2065: 'tmp2' : undeclared identifier
D:\mfc-heima-3day\SaleSystem\UserDlg.cpp(115) : error C2679: binary '=' : no operator defined which takes a right-hand operand of type 'class CString' (or there is no acceptable conversion)
D:\mfc-heima-3day\SaleSystem\UserDlg.cpp(116) : error C2679: binary '=' : no operator defined which takes a right-hand operand of type 'class CString' (or there is no acceptable conversion)
D:\mfc-heima-3day\SaleSystem\UserDlg.cpp(118) : error C2228: left of '.GetBuffer' must have class/struct/union type
D:\mfc-heima-3day\SaleSystem\UserDlg.cpp(118) : error C2228: left of '.GetBuffer' must have class/struct/union type
源码:
链接:https://pan.baidu.com/s/1Wtk8xY0ruh_-nHW_ES7RHg?pwd=52pj
提取码:52pj
|