Problem ze standardem C++17 w VS Code

0

Mam problem z ustawieniem standardu w VS Code dostaję taki błąd wpisując komendę: -std=c++17 w terminalu. Dodam ,że jest kod z tutoriala https://www.learncpp.com/
wersja gcc: gcc (GCC) 9.2.0 Dodałem Mingw-w64 do ścieżki. W czym leży problem?

-std=c++17 : The term '-std=c++17' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1

  • -std=c++17
  •   + CategoryInfo          : ObjectNotFound: (-std=c++17:String) [], CommandNotFoundException
      + FullyQualifiedErrorId : CommandNotFoundException
    
    
#include <array>
#include <iostream>
#include <string_view>
#include <tuple>
#include <type_traits>
 
namespace a::b::c
{
    inline constexpr std::string_view str{ "hello" };
}
 
template <class... T>
std::tuple<std::size_t, std::common_type_t<T...>> sum(T... args)
{
    return { sizeof...(T), (args + ...) };
}
//--------------------------------------------------------------------------
int main()
{
    auto [iNumbers, iSum]{ sum(1, 2, 3) };
    std::cout << a::b::c::str << ' ' << iNumbers << ' ' << iSum << '\n';
 
    std::array arr{ 1, 2, 3 };
 
    std::cout << std::size(arr) << '\n';
 
    return 0;
}
4

To jest parametr kompilatora, nie polecenie do wykonania – a ty próbujesz wykonać to jako polecenie. No to dostajesz że nie ma takiego polecenia: is not recognized as the name of a cmdlet, function, script file, or operable program.

0

Teraz mam coś takiego.
Na stronie gcc jest podane z jednym minusem:
To enable C++20 support, add the command-line parameter -std=c++20 (use -std=c++2a in GCC 9 and earlier) to your g++ command line. Or, to enable GNU extensions in addition to C++20 features, add -std=gnu++20.
At line:1 char:3

  • --std=c++17
  • ~
    Missing expression after unary operator '--'.
    At line:1 char:3
  • --std=c++17

Unexpected token 'std=c++17' in expression or statement.
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : MissingExpressionAfterOperator

2
Starling napisał(a):

Teraz mam coś takiego.

Na stronie gcc jest podane z jednym minusem:
To enable C++20 support, add the command-line parameter -std=c++20 (use -std=c++2a in GCC 9 and earlier) to your g++ command line. Or, to enable GNU extensions in addition to C++20 features, add -std=gnu++20.
At line:1 char:3

  • --std=c++17
  • ~
    Missing expression after unary operator '--'.
    At line:1 char:3
  • --std=c++17

Unexpected token 'std=c++17' in expression or statement.
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : MissingExpressionAfterOperator

Po pierwsze powinno być -std=c++17
Po drugie gdzie ty to wpisałeś? Czemu błąd jest taki, jakby ten parametr był interpretowany jako kod C++?

Dałeś linka do tutoriala https://www.learncpp.com/ na podstawie, którego to robisz - fajnie.
Ale ja nie będę przeszukiwał całego tutoriala, by znaleźć konkretny artykuł, który dotyczmy tego tematu/problemu.
Daj linka bezpośredniego do tekstu, na którym obecnie się wzorujesz, albo cytat tego testu.

Wklej JSon-a z konfiguracją VScode.

0

Wpisałem to w Powershell'u w VS code.
Link do artykułu:
https://www.learncpp.com/cpp-tutorial/configuring-your-compiler-choosing-a-language-standard/

Ustawienia:
{
"files.autoSave": "afterDelay",
"editor.formatOnSave": true,
"diffEditor.wordWrap": "on",
"editor.wordWrap": "on",
"liveServer.settings.donotShowInfoMsg": true,
"liveServer.settings.donotVerifyTags": true,
"C_Cpp.updateChannel": "Insiders",
"php.executablePath": "",
"workbench.editorAssociations": [
{
"viewType": "default",
"filenamePattern": "*.h"
}
],
"C_Cpp.default.cppStandard": "c++17"
}

2

Ta opcja to jest parametr kompilatora - kiedy kompilujesz swój program powinieneś wydać komendę w stylu g++ -std=c++17 mojplik.c - i to możesz zrobić rzeczywiście w terminalu w VSCode. Samo z siebie -std=c++17 nie jest komendą.

Jeżeli chcesz by ten parametr był automatycznie dodawany podczas gdy klikasz "run" w VSCode to to się zdaje się ustawia w tasks.json.

0

Wpisanie g++ -std=c++17 mojplik.cpp pomogło program się uruchomił dzięki z odpowiedź.

1 użytkowników online, w tym zalogowanych: 0, gości: 1