[Error] range-based ‘for‘ loops are not allowed in C++98 mode解决方案

前言

vector<int> postion;
// A
for(vector<int>::iterator i = postion.begin(); i < postion.end(); i++)
		cout << *i <<endl;
// B	
	for(int i : postion)
		cout << i <<endl;

代码A和代码B都是一样的作用:遍历输出容器postion的元素,很显然代码B更简洁。

代码B报错解决方法

工具 - 程序,添加 -std=c++11(前面有空格隔开),即可。
在这里插入图片描述