error C2275: “size_t”: 将此类型用作表达式非法(转)

该博客讨论了C语言要求变量声明在函数块头部,而C++则没有此限制。解决方案是确保在C++中变量声明位于其作用域的开始处。这有助于理解两种语言的语法区别。
1>d:\documents\visual studio 2010\projects\ches\ches\gghghg.c(22): error C2275: “Student”: 将此类型用作表达式非法 1> d:\documents\visual studio 2010\projects\ches\ches\gghghg.c(11) : 参见“Student”的声明 1>d:\documents\visual studio 2010\projects\ches\ches\gghghg.c(22): error C2146: 语法错误: 缺少“;”(在标识符“newStudent”的前面) 1>d:\documents\visual studio 2010\projects\ches\ches\gghghg.c(22): error C2065: “newStudent”: 未声明的标识符 1>d:\documents\visual studio 2010\projects\ches\ches\gghghg.c(24): error C2065: “newStudent”: 未声明的标识符 1>d:\documents\visual studio 2010\projects\ches\ches\gghghg.c(24): error C2224: “.id”的左侧必须具有结构/联合类型 1>d:\documents\visual studio 2010\projects\ches\ches\gghghg.c(28): error C2065: “newStudent”: 未声明的标识符 1>d:\documents\visual studio 2010\projects\ches\ches\gghghg.c(28): error C2224: “.name”的左侧必须具有结构/联合类型 1>d:\documents\visual studio 2010\projects\ches\ches\gghghg.c(28): error C2065: “newStudent”: 未声明的标识符 1>d:\documents\visual studio 2010\projects\ches\ches\gghghg.c(28): error C2224: “.name”的左侧必须具有结构/联合类型 1>d:\documents\visual studio 2010\projects\ches\ches\gghghg.c(28): warning C4133: “函数”: 从“FILE *”到“char *”的类型不兼容 1>d:\documents\visual studio 2010\projects\ches\ches\gghghg.c(28): error C2198: “fgets”: 用于调用的参数太少 1>d:\documents\visual studio 2010\projects\ches\ches\gghghg.c(29): error C2065: “newStudent”: 未声明的标识符 1>d:\documents\visual studio 2010\projects\ches\ches\gghghg.c(29): error C2224: “.name”的左侧必须具有结构/联合类型 1>d:\documents\visual studio 2010\projects\ches\ches\gghghg.c(29): error C2065: “newStudent”: 未声明的标识符 1>d:\documents\visual studio 2010\projects\ches\ches\gghghg.c(29): error C2224: “.name”的左侧必须具有结构/联合类型 1>d:\documents\visual studio 2010\projects\ches\ches\gghghg.c(29): error C2198: “strcspn”: 用于调用的参数太少 1>d:\documents\visual studio 2010\projects\ches\ches\gghghg.c(32): error C2065: “newStudent”: 未声明的标识符 1>d:\documents\visual studio 2010\projects\ches\ches\gghghg.c(32): error C2224: “.score”的左侧必须具有结构/联合类型 1>d:\documents\visual studio 2010\projects\ches\ches\gghghg.c(34): error C2065: “newStudent”: 未声明的标识符 1>d:\documents\visual studio 2010\projects\ches\ches\gghghg.c(34): error C2440: “=”: 无法从“int”换为“Student” 1>d:\documents\visual studio 2010\projects\ches\ches\gghghg.c(77): error C2143: 语法错误 : 缺少“;”(在“类型”的前面) 1>d:\documents\visual studio 2010\projects\ches\ches\gghghg.c(78): error C2143: 语法错误 : 缺少“;”(在“类型”的前面) 1>d:\documents\visual studio 2010\projects\ches\ches\gghghg.c(79): error C2065: “total”: 未声明的标识符 1>d:\documents\visual studio 2010\projects\ches\ches\gghghg.c(81): error C2065: “i”: 未声明的标识符 1>d:\documents\visual studio 2010\projects\ches\ches\gghghg.c(81): error C2065: “i”: 未声明的标识符 1>d:\documents\visual studio 2010\projects\ches\ches\gghghg.c(81): error C2065: “i”: 未声明的标识符 1>d:\documents\visual studio 2010\projects\ches\ches\gghghg.c(82): error C2065: “total”: 未声明的标识符 1>d:\documents\visual studio 2010\projects\ches\ches\gghghg.c(82): error C2065: “i”: 未声明的标识符 1>d:\documents\visual studio 2010\projects\ches\ches\gghghg.c(82): warning C4244: “+=”: 从“float”换到“int”,可能丢失数据 1>d:\documents\visual studio 2010\projects\ches\ches\gghghg.c(84): error C2065: “total”: 未声明的标识符 1>d:\documents\visual studio 2010\projects\ches\ches\gghghg.c(84): warning C4244: “return”: 从“int”换到“float”,可能丢失数据 该代码在VC c++2010上报错,但在vs上没有报错
04-01
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、付费专栏及课程。

余额充值