这里有这段简单的c++代码,没有下划线,但是当我编译它时,控制台在第10行显示4个错误,在第20行显示4个错误,在第21行显示3个错误。
//Comment
#include <iostream>
#include <vector>
#include <string>
#include "stdafx.h"
using namespace std;
string comb(vector<int> table) { //Line 10
string ret = "";
for (int i = 0; i < table.size(); i++) {
ret = ret + to_string(table[i]);
}
return ret;
}
int main()
{
vector<int> tab = { 3,4,5,6,7,99 };
cout << comb(tab);
}
注释掉#include "stdafx.h"
,你的代码没问题。
的例子:
//Comment
#include <iostream>
#include <vector>
#include <string>
//#include "stdafx.h"
using namespace std;
string comb(vector<int> table) {
string ret = "";
for (int i = 0; i < table.size(); i++) {
ret = ret + to_string(table[i]);
}
return ret;
}
int main()
{
vector<int> tab = { 3,4,5,6,7,99 };
cout << comb(tab);
}
我现在明白了,我把#include "stdafx.h"放在所有的#include下面。