I'm learning C++ using Visual Studio Code. I'm starting to pull my hair out trying to figure why the compiler won't recognize C++11 standards. The code + .json file + error are as follows:
#include <iostream>
#include <vector>
using namespace std;
int main() {
vector <int> vector_numbers;
for (int i : vector_numbers) {
vector_numbers[1] = i + 1;
}
for (int i : vector_numbers) {
cout << "The vector element at index [" << i << "] is " << vector_numbers.at(i) << endl;
}
return 0;
}
The contents of "args" parameter in tasks.json is
"args": [
"-std=c++11",
"-std=c++17",
"-std=c++20",
"-stdlib=libc++",
"-fcolor-diagnostics",
"-fansi-escape-codes",
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
]
and error is:
<REDACTED> % cd "<REDACTED PATH>" && g++ Vectors.cpp -o Vectors && "<REDACTED PATH>"Vectors
Vectors.cpp:9:16: warning: range-based for loop is a C++11 extension [-Wc++11-extensions]
for (int i : vector_numbers) {
^
Vectors.cpp:13:16: warning: range-based for loop is a C++11 extension [-Wc++11-extensions]
for (int i : vector_numbers) {
^
2 warnings generated.
Aucun commentaire:
Enregistrer un commentaire