在写Windows程序的时候使用CString 的话,就会出现error C2065: CString : 未声明的标识符...

本文介绍在Windows程序开发中遇到的CString未声明错误,并提供了解决方案:在主函数文件中包含atlstr.h头文件即可避免该错误。

在写Windows程序的时候使用CString 的话,就会出现error C2065: CString : 未声明的标识符

我是在主函数文件中#include <atlstr.h>,然后就可以了。

转载于:https://www.cnblogs.com/cappuccino/archive/2010/07/05/1771080.html

发生错误了已启动生成… 1>------ 已启动生成: 项目: ImageSystem, 配置: Debug Win32 ------ 1>ImageSystemDlg.cpp 1>C:\Users\John\source\repos\ImageSystem\ImageSystem\ImageSystemDlg.cpp(132,26): error C2065: “gt”: 未声明标识符 1>C:\Users\John\source\repos\ImageSystem\ImageSystem\ImageSystemDlg.cpp(132,28): error C2429: 语言功能 "if/switch 中的 init-statement" 需要编译器标志 "/std:c++17" 1>C:\Users\John\source\repos\ImageSystem\ImageSystem\ImageSystemDlg.cpp(141,23): error C2065: “gt”: 未声明标识符 1>C:\Users\John\source\repos\ImageSystem\ImageSystem\ImageSystemDlg.cpp(141,57): error C2660: “SetStretchBltMode”: 函数不接受 1 个参数 1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0\um\wingdi.h(4584,25): message : 参见“SetStretchBltMode”的声明 1>C:\Users\John\source\repos\ImageSystem\ImageSystem\ImageSystemDlg.cpp(142,26): error C2065: “gt”: 未声明标识符 1>C:\Users\John\source\repos\ImageSystem\ImageSystem\ImageSystemDlg.cpp(142,28): error C2143: 语法错误: 缺少“)”(在“;”的前面) 1>C:\Users\John\source\repos\ImageSystem\ImageSystem\ImageSystemDlg.cpp(142,28): error C2661: “ATL::CImage::StretchBlt”: 没有重载函数接受 1 个参数 1>C:\Users\John\source\repos\ImageSystem\ImageSystem\ImageSystemDlg.cpp(142,30): error C2065: “m_hDC”: 未声明标识符 1>C:\Users\John\source\repos\ImageSystem\ImageSystem\ImageSystemDlg.cpp(142,54): error C2059: 语法错误:“)” 1>C:\Users\John\source\repos\ImageSystem\ImageSystem\ImageSystemDlg.cpp(143,9): error C2065: “gt”: 未声明标识符 1>C:\Users\John\source\repos\ImageSystem\ImageSystem\ImageSystemDlg.cpp(143,38): error C2660: “SetStretchBltMode”: 函数不接受 1 个参数 1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0\um\wingdi.h(4584,25): message : 参见“SetStretchBltMode”的声明 1>已完成生成项目“ImageSystem.vcxproj”的操作 - 失败。 ========== 生成: 成功 0 个,失败 1 个,最新 0 个,跳过 0 个 ==========
09-04
void CMFCApplication2Dlg::SendCurrentData() { CString strData; m_editSend.GetWindowText(strData); // 获取0D0A添加状态 BOOL bAddCRLF = (m_checkAddCRLF.GetCheck() == BST_CHECKED); if (m_radioHex.GetCheck() == BST_CHECKED) { // HEX模式处理 strData.Remove(' '); int nLen = strData.GetLength() / 2; int nTotalLen = nLen + (bAddCRLF ? 2 : 0); std::vector<BYTE> buffer(nTotalLen); for (int i = 0; i < nLen; i++) { CString hex = strData.Mid(i * 2, 2); sscanf_s(hex, "%02hhX", &buffer[i]); } // 添加0D0A if (bAddCRLF) { buffer[nLen] = 0x0D; buffer[nLen + 1] = 0x0A; } SendRawData(buffer.data(), nTotalLen); } else { // ASCII模式处理 if (bAddCRLF) strData += _T("\r\n"); CStringA ansiData(strData); SendRawData(ansiData.GetString(), ansiData.GetLength()); } }1>------ 已启动生成: 项目: MFCApplication2, 配置: Debug Win32 ------ 1>MFCApplication2.cpp 1>MFCApplication2Dlg.cpp 1>c:\users\administrator\desktop\mfcapplication2\mfcapplication2\mfcapplication2dlg.cpp(252): error C2039: “vector”: 不是“std”的成员 1>c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.16.27023\include\type_traits(17): note: 参见“std”的声明 1>c:\users\administrator\desktop\mfcapplication2\mfcapplication2\mfcapplication2dlg.cpp(252): error C2065: “vector”: 未声明标识符 1>c:\users\administrator\desktop\mfcapplication2\mfcapplication2\mfcapplication2dlg.cpp(252): error C2275: “BYTE”: 将此类型用作表达式非法 1>c:\program files (x86)\windows kits\10\include\10.0.17763.0\shared\minwindef.h(158): note: 参见“BYTE”的声明 1>c:\users\administrator\desktop\mfcapplication2\mfcapplication2\mfcapplication2dlg.cpp(252): error C3861: “buffer”: 不到标识符 1>c:\users\administrator\desktop\mfcapplication2\mfcapplication2\mfcapplication2dlg.cpp(255): error C2065: “buffer”: 未声明标识符 1>c:\users\administrator\desktop\mfcapplication2\mfcapplication2\mfcapplication2dlg.cpp(255): error C2664: “int sscanf_s(const char *const ,const char *const ,...)”: 无法将参数 1 从“CString”转换为“const char *const ” 1>c:\users\administrator\desktop\mfcapplication2\mfcapplication2\mfcapplication2dlg.cpp(255): note: 没有可用于执行该转换的用户定义的转换运算符,或者无法调用该运算符 1>c:\users\administrator\desktop\mfcapplication2\mfcapplication2\mfcapplication2dlg.cpp(260): error C2065: “buffer”: 未声明标识符 1>c:\users\administrator\desktop\mfcapplication2\mfcapplication2\mfcapplication2dlg.cpp(261): error C2065: “buffer”: 未声明标识符 1>c:\users\administrator\desktop\mfcapplication2\mfcapplication2\mfcapplication2dlg.cpp(264): error C2065: “buffer”: 未声明标识符 1>c:\users\administrator\desktop\mfcapplication2\mfcapplication2\mfcapplication2dlg.cpp(338): error C2600: “CMFCApplication2Dlg::~CMFCApplication2Dlg”: 不能定义编译器生成的特殊成员函数(必须首先在类中声明) 1>正在生成代码... 1>已完成生成项目“MFCApplication2.vcxproj”的操作 - 失败。 ========== 生成: 成功 0 个,失败 1 个,最新 0 个,跳过 0 个 ==========
10-18
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符  | 博主筛选后可见
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值