首页 > 解决方案 > VS 代码给出的设置片段中的错误

问题描述

我最近开始使用 VS Code。他们的网页给出了以下从 C++ 开始的片段

#include <iostream>
#include <vector>
#include <string>

using namespace std;

int main()
{
    vector<string> msg {"Hello", "C++", "World", "from", "VS Code", "and the C++ extension!"};

    for (const string& word : msg)
    {
        cout << word << " ";
    }
    cout << endl;
}

但是当我运行它时,它给出了以下错误:

test.cpp:9:23: error: expected ';' at end of declaration
    vector<string> msg {"Hello", "C++", "World", "from", "VS Code", "and the C++ extension!"};
                      ^
                      ;
test.cpp:11:29: warning: range-based for loop is a C++11 extension [-Wc++11-extensions]
    for (const string& word : msg)

我对使用这个 IDE 以及一般使用 C++ 完全陌生。我需要安装任何库来运行它吗?

谢谢

标签: c++visual-studio-code

解决方案


推荐阅读