I am able to compile and execute my code successfully. However, VSCode keeps showing me the error message:
namespace std has no member "sqrt".
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
}
I see two problems with your c_cpp_properties.json
:
compilerPath
attribute.intelliSenseMode
as msvc-x64
but are clearly using gcc
include paths.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
}
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With