【发布时间】:2015-03-01 19:08:46
【问题描述】:
当我尝试构建此代码时,它会显示错误! 也不知道怎么解决!!
错误 C3531:“x”:类型包含“auto”的符号必须具有初始化程序
错误 C2143:语法错误:在 ':' 之前缺少 ','
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <map>
#include <cctype>
using namespace std;
int main(){
ifstream in("input.txt");
ofstream out("output.txt");
string s;
int line=0;
vector<string> vec(1,"dummy");
multimap<int,int> M;
while(getline(in, s)){
line++;
vec.push_back(s);
if(line%12==10){
string temp="";
for(auto x:s) if(isdigit(x)) temp+=x;
int key = stoi(temp);
M.insert(make_pair(key,line));
}
}
auto it = M.rbegin();
while(it != M.rend()){
int i = it->second;
int start = (int(i/12))*12 +1;
for(int j=1; j<=12; j++) out << vec.at(start++) << "\n";
it++;
}
in.close();
out.close();
return 0;
}
【问题讨论】:
-
您使用的是什么版本的 Visual Studio?看起来它不支持基于范围的
for。 -
现在是 2010 年?!!那我怎么解决呢?!
-
升级到 VS2012 或更高版本。或者停止使用基于范围的
for循环 -
@Kurd 不,今年是 2015 年
-
正如 Praetorian 所说,基于范围的 for 循环仅在 VS2012 及更高版本中实现。如果您不必使用 VS,g++(版本 >= 4.7)支持它们。
标签: c++