visual studio 中解决中文字符 提示 “无法识别的标记”错误或者带注释无法编译的解决方案
#include <iostream>
#include <string>
using namespace std;
struct Student{//这里注释带中文会报错
string name;
int score;
// 重载小于运算法,定义Student之间的比较方式
// 如果分数相等,则按照名字的字母序排序
// 如果分数不等,则分数高的靠前
bool operator<(const Student& otherStudent){
return score != otherStudent.score ?
score > otherStudent.score : name < otherStudent.name;
}
“无法识别的标记”出现原因之一是注释带有中文,且中文格式可能是utf-8格式。
解决方案:用记事本形式打开源码文件,另存为带有BOM的utf-8格式,亲测有效,重新打开代码即可运行。