C++ 20 setting in VS code (Ubuntu)

Chandra sekar Veerappan
2 min readOct 28, 2023

--

Trying a simple C++ 20 code example with spaceship operator — 3-way comparisons:

The three-way comparison operator expressions is of the form:

lhs <=> rhs

The spaceship operator looks like <=> and its official C++ name is the 3-way comparison operator. It is called so because it is used by comparing two objects, then comparing that result with 0: Interesting,right !!

(x <=> y) < 0 is true if x < y
(x <=> y) > 0 is true if x > y
(x <=> y) == 0 is true if x and y are equal/equivalent.

More on here -https://www.geeksforgeeks.org/features-of-c-20/

I am not going explaining this…but wish to solve the error or how to set VS code correctly. The default settings gives error, got some help from Google search. Someone suggested the necessary settings.. but i have mistakenly set C++ 17 and getting the error. Even you did not set the specific C++ 17 setting, still gives the 2 error “expected primary-expression before ‘>’ token…

C++ error

Here is the quick steps, Please see the .VS code settings on the root folder of the c++ code.In my case, it is /home/user/Documents/.vscode/..

As seen below screen shot below and look for TWO json files. c_cpp_properties.json and tasks.json. And change the cStandard and cppStandard and later args in tasks.json

c_cpp_properties.json
tasks.json

That all.. May be your settings may be bit different. Hope this helps and helps pay with C++ 20 features. Cheers! :)

--

--