相关疑难解决方法(0)

如何在 VSCode C++ 扩展中启用 C++17 支持

我一直在 std::string_view 上出现错误曲线,但我能够构建得很好。有没有办法告诉智能感知或 C++ linter 使用 C++17?

我得到的具体错误是:

namespace "std" has no member "string_view"
Run Code Online (Sandbox Code Playgroud)

c++ visual-studio-code c++17 vscode-settings

31
推荐指数
3
解决办法
2万
查看次数

VSCode C++ Intellisense 无法识别 C++20 功能

我尝试运行类似的代码

#include <string>
#include <iostream>

int main() {
    std::string str = "This is a string";
    std::cout << str.starts_with("name");
}
Run Code Online (Sandbox Code Playgroud)

但是intellisense会报错

“std::__cxx11::basic_string<char, std::char_traits, std::allocator>”没有成员“starts_with” C/C++(135) [6,9]

它仍然可以构建并产生正确的结果。它还可以在头文件中找到实现。但是宏__cplusplus是定义的,因为201703L 我在构建时已经添加了命令-std=c++20,为什么会发生这种情况?

编译器:msys2编译的minGW 11.2

c++ visual-studio-code c++20

12
推荐指数
1
解决办法
6243
查看次数

Visual Studio Code c ++ 11扩展警告

我正在学习c ++,正在使用Mac的Visual Studio代码。我使用Code Runner运行程序。我的问题是,当我使用c ++ 11中的诸如“ auto”之类的变量声明时,Visual Studio代码会给我这样的警告,但是如果我尝试在Xcode或Eclipse上运行它,则不会:

warning: 'auto' type specifier is a C++11 extension [-Wc++11-extensions]
for(auto y: nstrVec)
Run Code Online (Sandbox Code Playgroud)

这是必要的程序:

#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <numeric>
#include <sstream>

int main(){

std::vector<std::string> nstrVec(10);

std::string str("I'm a string");
nstrVec[0] = str;

std::cout << str.at(0) << "\n";
std::cout << str.front() << " " << str.back() << "\n";
std::cout << "Length " << str.length() << "\n";
// copies all characters after the fourth 
std::string str2(str, 4);

for(auto y: nstrVec) …
Run Code Online (Sandbox Code Playgroud)

c++ macos visual-studio-code

8
推荐指数
6
解决办法
4940
查看次数

如何在 vscode 中使用 C++20?

我想在 vscode 中使用 C++20,因为我想在 unordered_set 上使用 .contains,但是当我尝试它时,我得到了但 error C2039: 'contains': is not a member of 'std::unordered_set 我不明白为什么,因为我已经继续使用 c_cpp_properties.json 并指定使用 c++20 但它似乎仍然不起作用,而且我在 vscode 上找不到任何关于更改 C++ 版本的任何内容。

编译器版本: 19.25.28614 for x86

c++ visual-studio-code

6
推荐指数
2
解决办法
5019
查看次数

如何找到我的编译器使用的 C++ 语言标准的默认版本并更改它?

我想知道当我执行类似g++ main.cpp.

我知道我可以运行g++ -v编译器版本,例如返回:

Apple clang version 14.0.0 (clang-1400.0.29.202)
Target: arm64-apple-darwin22.1.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
Run Code Online (Sandbox Code Playgroud)

但我不确定这里使用的默认 C++ 语言版本是什么。

我也知道我可以用来-std=c++(version)更改它,但是,最好将默认值设置为 c++20 以保持最新状态并且不必使用标志。

c++ g++ clang

3
推荐指数
1
解决办法
2707
查看次数

如何为C ++ 14 / C ++ 17设置VS代码

我试图从工作区中运行一个.cpp文件,但是给了我关于不添加c ++ 11 / higher标志的错误,但是我将它们添加到task.json中

错误

[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 …
Run Code Online (Sandbox Code Playgroud)

c++ visual-studio-code vscode-settings vscode-tasks

0
推荐指数
2
解决办法
1921
查看次数

C++ VS Code 无法识别语法,无法运行代码

我正在使用课程所需的特定语法,但是当我在 VS Code 中使用此 C++ 语法时,它不起作用并会引发错误。

以下是无效语法的示例:

error: expected ';' at end of declaration
        int i {0}; 
             ^
             ;
Run Code Online (Sandbox Code Playgroud)

当我将其更改为int i = 0;错误时,错误就消失了。

它特别不识别{}设置默认变量值的语法。我ssh在本课程中使用登录名,语法在 中运行良好ssh,但在 VS Code 中不起作用。

我尝试通过执行此线程中的最佳答案将 VS Code C++ 版本更改为 C++17 ,但它仍然无法识别语法。

我是否使用了不正确的语法,或者有办法解决这个问题吗?

c++ macos visual-studio-code c++17

0
推荐指数
1
解决办法
1007
查看次数