I keep on getting error squiggles on std::string_view, but I am able to build just fine. Is there a way to tell intellisense or the C++ linter to use C++17?
The specific error I get is:
namespace "std" has no member "string_view"
I keep on getting error squiggles on std::string_view, but I am able to build just fine. Is there a way to tell intellisense or the C++ linter to use C++17?
The specific error I get is:
namespace "std" has no member "string_view"
This has become much easier now. Search for cppstandard
in your vs code extension settings and choose the version of C++ you want the extension to use from the drop down.
In order to make sure your debugger is using the same version, make sure you have something like this for your tasks.json
, where the important lines are the --std
and the line after that defines the version.
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: g++ build active file",
"command": "/usr/bin/g++",
"args": [
"-std=c++17",
"-I",
"${fileDirname}",
"-g",
"${fileDirname}/*.cpp",
"-o",
"${workspaceFolder}/out/${fileBasenameNoExtension}.o"
],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": ["$gcc"],
"group": {
"kind": "build",
"isDefault": true
}
}
],
"version": "2.0.0"
}
Note that if you're copying the above tasks.json
directly, you'll need to have a folder named out
in your workspace root.
There's a posting in their GitHub issue tracker about this: std::string_view intellisense missing (CMake, VC++ 2017).
In another issue, it is said that the extension defaults to C++17, but does not yet support all of C++17 features: Setting C++ standard.
This is confirmed by c_cpp_properties.json Reference Guide, where an option is listed cppStandard
which defaults to C++17. (To edit this file, press Ctrl + Shift + P and type in C/CPP: Edit Configurations
).
It appears, then, they just don't have full support yet.
Just an updated. I got this issue as well.
I solve it by adding c_cpp_properties.json
Ctrl + Shift + P then select C/C++:Edit Configurations (JSON)
Adjust the content for cStandard
and cppStandard
:
"cStandard": "gnu17",
"cppStandard": "gnu++17",
For people trying out on Linux and having GCC 7.5.0 installed, this worked for me.
Do these two steps to enable the linter to acknowledge the c++17 writings and for the compiler to pick up the c++17.
C/C++:Edit Configurations (JSON)
, and change the default values for these two fields to:"cStandard": "gnu18", "cppStandard": "gnu++17",
tasks.json
file inside .vscode
directory and add the following statements to the args
key:"--std", "c++17"
If you're unable to enable even after trying the solutions by @Marc.2377 and @W Kenny, do the following
tasks.json
in the .vscode
folder"--std","c++17"
under "args:"
tasks.json
After trying many things I have found probably a solution for people using CMake and willing to edit the CMakeLists.txt
file.
I just put the following line at the beginning of my CMakeLists.txt
set (CMAKE_CXX_STANDARD 17)
You can check your c++ version by doing:
cout << __cplusplus ;
and the 3rd and 4th number gives you the version of c++ you are using.
For example:
cout << __cplusplus ;
201703
means you are using c++ 17
and
cout << __cplusplus ;
201402
means you are using c++ 14
I think that there must be an easier solution but I could not find it yet.
Additional to set cppStandard
to gnu++17
in c_cpp_properties.json
mentioned in other posts, you need to change the __cplusplus
-define to the corresponding value (e.g. 201703L
)
Like that:
{
"version": 4,
"configurations": [
{
// ...
"cStandard": "gnu17",
"cppStandard": "gnu++17",
"defines": [
// ...
"__cplusplus=201703L"
// ...
]
}
]
}
I have tried editing the settings of C_Cpp>Default: Cpp Standard
and C Standard
to specify them as C++17 standard
. However, that did not work.
Then I found a .vscode
folder in my project directory with a c_cpp_properties.json
file. In there I found settings that I had not edited, where I specified to use the C++11 standard
. When I changed it, I found that the problem was gone.
If you find that the answer above doesn't work, maybe we made the same mistake.
Check your version of g++ using g++ --version
on the command line. If it is like version 6 or 7 then you need to update to a newer version with mingw. I used mysys2 to do this and now I do not have the same problem.