如何修复命名空间“std"没有成员“sqrt"在 VSCode 中? [英] How to fix namespace "std" has no member "sqrt" in VSCode?
问题描述
我能够成功编译和执行我的代码.但是,VSCode 不断向我显示错误消息:
I am able to compile and execute my code successfully. However, VSCode keeps showing me the error message:
命名空间 std 没有成员sqrt".
namespace std has no member "sqrt".
我调整了properties.json.请建议为什么 vscode 显示此错误.我试过谷歌搜索但无济于事.
I adjusted the properties.json. Please advice why is the vscode showing this error. I tried googling but no avail.
#include <iostream>
#include <cmath>
#include <complex>
int main() {
double a,b,c;
int root1, root2;
std::cout<<"Enter a: \n";
std::cin >> a;
std::cout<<"Enter b: \n";
std::cin >> b;
std::cout<<"Enter c: \n";
std::cin >> c;
root1 = (-b + std::sqrt (b*b - 4*a*c)) / (2*a);
std::cout<<"Root 1 Number: " << root1 << "\n";
root2 = (-b - std::sqrt (b*b - 4*a*c)) / (2*a);
std::cout<<"Root 2 Number: " << root2 << "\n";
}
json:
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceRoot}",
"C:/MinGW/lib/gcc/mingw32/8.2.0/include/c++",
"C:/MinGW/lib/gcc/mingw32/8.2.0/include/c++/backward",
"C:/MinGW/lib/gcc/mingw32/8.2.0/include",
"C:/MinGW/lib/gcc/mingw32/8.2.0/include/c++/tr1",
"C:/MinGW/lib/gcc/mingw32/8.2.0/include/c++/tr2"
],
"defines": [
"_DEBUG",
"UNICODE",
"__GNUC__=6",
"__cdecl=__attribute__((__cdecl__))"
],
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "msvc-x64",
"browse": {
"path": [
"${workspaceRoot}",
"C:/MinGW/lib/gcc/mingw32/8.2.0/include/c++",
"C:/MinGW/lib/gcc/mingw32/8.2.0/include/c++/backward",
"C:/MinGW/lib/gcc/mingw32/8.2.0/include",
"C:/MinGW/lib/gcc/mingw32/8.2.0/include/c++/tr1",
"C:/MinGW/lib/gcc/mingw32/8.2.0/include"
]
}
}
],
"version": 4
}
推荐答案
我发现您的 c_cpp_properties.json
有两个问题:
I see two problems with your c_cpp_properties.json
:
- 没有
compilerPath
属性. - 您有
intelliSenseMode
作为msvc-x64
但显然使用了gcc
包含路径.
- There is no
compilerPath
attribute. - You have
intelliSenseMode
asmsvc-x64
but are clearly usinggcc
include paths.
可能您想通过提供 g++.exe
的完整路径来修复 (1) 和 (2) 通过将 intelliSenseMode
更改为 gcc-x86代码>.类似的东西:
Probably you want to fix (1) by providing the full path to g++.exe
and (2) by changing intelliSenseMode
to gcc-x86
. Something like:
{
"configurations": [
{
...
"compilerPath": "C:/MinGW/bin/g++.exe",
"intelliSenseMode": "gcc-x86",
...
}
],
"version": 4
}
我还建议您阅读 C++ 入门 指南,如果您还没有.即使您最终不想按照教程的方式进行设置,拥有一个有效的配置来比较出现问题时的情况也是很有价值的.
I also suggest going through the Getting Started with C++ guide if you haven't already. Even if you don't ultimately want to set things up the way the tutorial does, it is valuable to have a working configuration to compare to when things go wrong.
此外,在命令面板 (Ctrl+Shift+P) 中,尝试运行C/C++:日志诊断".将您在该输出中看到的内容与以下输出进行比较:
Also, in the Command Palette (Ctrl+Shift+P), try running "C/C++: Log Diagnostics". Compare what you see in that output to the output of:
$ touch empty.c
$ g++ -v -E -dD empty.c
理想情况下,您希望它们尽可能匹配.
Ideally, you want those to match as closely as possible.
这篇关于如何修复命名空间“std"没有成员“sqrt"在 VSCode 中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!