J'ai essayé d'exécuter un fichier .cpp à partir de l'espace de travail mais en me donnant cette erreur de ne pas ajouter d'indicateurs c ++ 11 / supérieur, mais je les ai ajoutés dans task.json
Erreur p>
{ "name": "Win32", "includePath": [ "${workspaceFolder}" ], "defines": [ "_DEBUG", "UNICODE", "_UNICODE" ], "intelliSenseMode": "clang-x64", "browse": { "path": [ "${workspaceFolder}" ], "limitSymbolsToIncludedHeaders": true, "databaseFilename": "" }, "compilerPath": "F:\\Program Files (x86)\\CodeBlocks\\MinGW\\bin\\gcc.exe", "cStandard": "c11", "cppStandard": "c++17" }
Message d'erreur : c_cpp_properties: [Running] cd "c:\Users\Nuhash\Desktop\test\" && g++ main.cpp -o main && "c:\Users\Nuhash\Desktop\test\"main
main.cpp:8:1: error: expected unqualified-id before 'using'
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
^
main.cpp:10:1: error: expected unqualified-id before 'using'
using ordered_set_rev = tree<T, null_type, greater<T>, rb_tree_tag, tree_order_statistics_node_update>;
^
main.cpp:12:1: error: expected unqualified-id before 'using'
using dijkstra = priority_queue<T, vector<T>, greater<T>>;
^
main.cpp:62:31: warning: variadic templates only available with -std=c++11 or -std=gnu++11
template <typename T, typename... Args>
^
main.cpp:63:52: warning: variadic templates only available with -std=c++11 or -std=gnu++11
void err(istream_iterator<string> it, T a, Args... args) {
{
"version": "2.0.0",
"tasks": [
{
"label": "build hello world",
"type": "shell",
"command": "g++",
"args": [
"-g",
"-o",
"test",
"-std=c++14",
"main.cpp"
],
"group": {
"kind": "build",
"isDefault": true
},
"problemMatcher": [
"$gcc"
]
}
]
}
[Running] cd "c:\Users\Nuhash\Desktop\test\" && g++ main.cpp -o main && "c:\Users\Nuhash\Desktop\test\"main
main.cpp:8:1: error: expected unqualified-id before 'using'
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
^
main.cpp:10:1: error: expected unqualified-id before 'using'
using ordered_set_rev = tree<T, null_type, greater<T>, rb_tree_tag, tree_order_statistics_node_update>;
^
main.cpp:12:1: error: expected unqualified-id before 'using'
using dijkstra = priority_queue<T, vector<T>, greater<T>>;
^
main.cpp:62:31: warning: variadic templates only available with -std=c++11 or -std=gnu++11
template <typename T, typename... Args>
^
main.cpp:63:52: warning: variadic templates only available with -std=c++11 or -std=gnu++11
void err(istream_iterator<string> it, T a, Args... args) {
4 Réponses :
Définissez cppStandard
sur c ++ 17
ou c ++ 14
respectivement.
Vous avez besoin de l'extension C ++ pour cela https://github.com/Microsoft/vscode-cpptools < / a>
J'ai déjà cette extension et cppStandard est défini sur c ++ 17
J'ai ajouté le code runner et ajouté ceci dans settings.json Semble fonctionner pour moi: D
"code-runner.executorMap": { "cpp": "cd $dir && g++ -std=c++17 $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt", },
Ajoutez "-std = c ++ 11",
à la valeur "args"
dans votre fichier task.json
. Cela devrait résoudre votre problème C ++ 11.
Donc finalement votre task.json ressemblera à
{ "version": "2.0.0", "tasks": [ { "label": "build hello world", "type": "shell", "command": "g++", "args": [ "-g", "-std=c++11", "-std=c++14", "main.cpp", "-o", "test" ], "group": { "kind": "build", "isDefault": true }, "problemMatcher": [ "$gcc" ] } ] }
Je n'ai pas ajouté de fichiers d'en-tête MinGW dans c_cpp_properties.json. Après ça a bien fonctionné c_cpp_properties.json ressemble à ceci ...
{ "version": "2.0.0", "tasks": [ { "type": "shell", "label": "g++.exe build active file", "command": "g++.exe -std=c++14 -g ${file} -o ${fileDirname}\\${fileBasenameNoExtension}.exe && ${fileDirname}\\${fileBasenameNoExtension}.exe", "options": { "cwd": "C:\\Program Files (x86)\\CodeBlocks\\MinGW\\bin" }, "problemMatcher": [ "$gcc" ], "group": "build" } ] }
et changez mon tasks.json en ceci ...
{ "configurations": [ { "name": "Win32", "includePath": [ "${workspaceFolder}/**", "C:\\Program Files (x86)\\CodeBlocks\\MinGW\\include" ], "defines": [ "_DEBUG", "UNICODE", "_UNICODE" ], "compilerPath": "\"C:\\Program Files (x86)\\CodeBlocks\\MinGW\\bin\\g++.exe\"", "cStandard": "c11", "cppStandard": "c++17", "intelliSenseMode": "gcc-x86" } ], "version": 4 }
maintenant il construit et exécute le fichier compilé
êtes-vous sûr que le
tasks.json
est correct? il ne correspond pas au message d'erreurOui, cela fonctionnait bien. Ensuite, j'ai réinstallé Windows et vs code, mais cela ne fonctionne pas pour une raison quelconque. Tâche. json était dans le dossier depuis le début ...
J'appuie le commentaire d'Alan. La sortie de construction
[Running] cd "c: \ Users \ Nuhash \ Desktop \ test \" && g ++ main.cpp -o main && "c: \ Users \ Nuhash \ Desktop \ test \" main
ne correspond pas à votretasks.json
.Oui, mais Tasks.json est correct. Je ne sais pas pourquoi la commande ne correspond pas avec le tasks.json, je l'ai recréé plusieurs fois. Quoi qu'il en soit, je l'ai corrigé en modifiant la configuration du programme d'exécution de code dans settings.json