我能够成功编译并执行我的代码。但是,VSCode不断向我显示错误消息:
namespace std没有成员“ sqrt”。
我调整了properties.json。请告知为什么vscode显示此错误。我尝试使用Google搜索,但无济于事。
#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
}
答案 0 :(得分:1)
我发现您的c_cpp_properties.json
存在两个问题:
compilerPath
属性。intelliSenseMode
设为msvc-x64
,但显然使用的是gcc
包含路径。可能您想通过提供g++.exe
的完整路径来修复(1),并通过将intelliSenseMode
更改为gcc-x86
来修复(2)。像这样:
{
"configurations": [
{
...
"compilerPath": "C:/MinGW/bin/g++.exe",
"intelliSenseMode": "gcc-x86",
...
}
],
"version": 4
}
我还建议您仔细阅读Getting Started with C++指南。即使您最终不希望按照本教程的方式进行设置,也值得进行工作配置以与出现问题时进行比较。
此外,在命令面板(Ctrl + Shift + P)中,尝试运行“ C / C ++:日志诊断”。将您在输出中看到的与以下输出进行比较:
$ touch empty.c
$ g++ -v -E -dD empty.c
理想情况下,您希望它们尽可能地匹配。