关于auto(求助)
  • 板块灌水区
  • 楼主Skywalker2187
  • 当前回复0
  • 已保存回复0
  • 发布时间2023/12/22 20:03
  • 上次更新2023/12/22 20:04:21
查看原帖
关于auto(求助)
906525
Skywalker2187楼主2023/12/22 20:03
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <vector>

typedef std::pair<bool,bool> magnet;
// typedef long long LL;
// const int N=;

using namespace std;

int n;// number
vector<magnet> st;// status

int main()
{
	// #ifndef ONLINE_JUDGE
	// 	freopen(".in","r",stdin);
	// 	freopen(".out","w",stdout);
	// #endif
	
	// input
	scanf("%d",&n);
	// input magnet
	for(int i=0;i<n;i++)
	{
		int l,r;
		scanf("%d%d",&l,&r);
		st.push_back(make_pair(l,r));
	}

	for(auto& p:st)
	{
		printf("%d ",p);
	}
	puts("\n");

	// // count
	// int cnt=0;
	// for(int i=1;i<n;i++)
	// {
	// 	if(st[i].first==st[i-1].second)
	// 	{
	// 		cnt++;
	// 	}
	// }

	// // output
	// printf("%d\n",cnt);

	return 0;
}

当我debug这段代码时,vscode提示我:

error: range-based 'for' loops are not allowed in C++
98 mode
  for(auto& p:st)
              ^

可我的编译命令是:

cd "f:\wty's_folder\vscode_en_folder\" ; i
f ($?) { g++ CF344A_Magnets.cpp -o CF344A_Magnets } ; if ($?) { .\CF344A_Magnet
s -std=c++14 -O2 -Wall -static }

使用了-std=c++14\texttt{\color{red}{-std=c++14}},求dalao解释为何会CE

2023/12/22 20:03
加载中...