情况:

在基于范围内对数组进行遍历时,发现不能运行: 

    for(int&e:array)  C++11的新特性,对一个范围内的元素进行有序访问,更方便的用法。

 

// 了解基于范围的for循环
#include <iostream>
using namespace std;


int main(){
    int array[3]={1,2,3};
    for(int&e:array){
        e += 2;
        cout<<e<<endl;
    }
    system("pause");
    return 0; 
}

解决:

改动task.json中的配置文件

 "args": [
                "-g",
                "-Wall",
                "-std=c++11",
                "${file}",
                "-o",
                "${fileBasenameNoExtension}.exe"],//支持c++ 11编译命令参数

重启VScode,然后再运行程序即可。

 

Logo

腾讯云面向开发者汇聚海量精品云计算使用和开发经验,营造开放的云计算技术生态圈。

更多推荐