I am having an odd issue. I am working in C++ and I have coderunner installed and the basic C/C++ extension from Microsoft, but I am having an issue with my debugger.
#include <iostream>
#include <vector>
using namespace std;
int main()
{
vector<int> numbers{10,20,30,40,50};
for(int i = 0; i < numbers.size(); i++)
{
cout << numbers[i] << endl;
}
return 0;
}
At the moment hit Run Code it runes just fine displaying the output I was expecting, but when I run the debugger I choose g++. This is what displays in the debug console:
But I still have a problem listed as:
vec.cpp:7:24: error: expected ';' at end of declaration
vector<int> numbers{10,20,30,40,50};
^
;
1 error generated.
Build finished with error(s).
It seems to be running an older version of C++, but my configurations are as list
"C_Cpp_Runner.cCompilerPath": "clang",
"C_Cpp_Runner.cppCompilerPath": "clang++",
"C_Cpp_Runner.cppStandard": "c++17",
"C_Cpp_Runner.cStandard": "c17",
"C_Cpp_Runner.debuggerPath": "lldb",
"C_Cpp.default.cppStandard": "c++17",
"C_Cpp.default.cStandard": "c17",
// "liveServer.settings.CustomBrowser": "chrome",
"code-runner.executorMap":{
"cpp": "cd $dir && g++ -std=c++17 $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt",
}
Any ideas on why this would happen? Really confused why it would execute in the debug console, but not in the debugger. My compilers, g++ and clang++ are both up to date.
If the compiler supports C++11 standards then vector<int> numbers{1, 2, 3};
can be used.
You should not get this error when you try the following usage:
std::vector<int> numbers;
numbers.push_back(10);
numbers.push_back(20);
numbers.push_back(30);
numbers.push_back(40);
numbers.push_back(50);
If you are using Clang compiler you should use the following command to compile:
clang++ -std=c++11 -stdlib=libc++ vec.cpp
You can learn about the clang++
command's options by reading the "Clang Command Line Reference".