I have configured my vscode to use c++ on Linux. Recently i want to write a new cpp program, I followed the MS VScode tutorial, but when I copy the code to VScode, there is a red underline and hint like this: the error
However, I can build it and even run it correctly without error:run build tasks run it in terminal
When I debug it, the error occurs.
{
"resource": "/home/aqachun/Documents/Projects/cpp/vscodeTest/helloworld.cpp",
"owner": "C/C++",
"severity": 8,
"message": "no instance of constructor \"std::vector<_Tp, _Alloc>::vector [with _Tp=std::string, _Alloc=std::allocator<std::string>]\" matches the argument list -- argument types are: (const char [6], const char [4], const char [6], const char [5], const char [8], const char [23])",
"startLineNumber": 9,
"startColumn": 24,
"endLineNumber": 9,
"endColumn": 24
}
this is my c_cpp_properties.json:
{
"configurations": [
{
"name": "Linux",
"defines": [],
"compilerPath": "/usr/bin/gcc",
"includePath": [
"${default}",
"/usr/lib/gcc/x86_64-pc-linux-gnu/9.2.0/../../../../include/c++/9.2.0",
"/usr/lib/gcc/x86_64-pc-linux-gnu/9.2.0/../../../../include/c++/9.2.0/x86_64-pc-linux-gnu",
"/usr/lib/gcc/x86_64-pc-linux-gnu/9.2.0/../../../../include/c++/9.2.0/backward",
"/usr/lib/gcc/x86_64-pc-linux-gnu/9.2.0/include",
"/usr/local/include",
"/usr/lib/gcc/x86_64-pc-linux-gnu/9.2.0/include-fixed",
"/usr/include"
],
"cppStandard": "c++17",
"cStandard": "c11"
}
],
"version": 4
}
and my code:
#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;
}