What am I doing wrong in trying to get vscode working?

Viewed 25

I've followed multiple tutorials and followed every step but I believe I am missing something because I am constantly encountering unexpected errors in code that I copy verbatim.

Example: This is a code I have copied

#include <iostream>

int main()[
    auto result = (10 <=> 20) > 0;
    std::cout << result << std::endl;
]

and these are the errors I get when I try to 'run task'

C:\msys64\mingw642\bin\g++.exe -fdiagnostics-color=always -g -std=c++20 C:\Users\Pease\Documents\codes\projects\main.cpp -o C:\Users\Pease\Documents\codes\projects\main.exe
C:\Users\Pease\Documents\codes\projects\main.cpp:4:5: error: expected primary-expression before 'auto'
    4 |     auto result = (10 <=> 20) > 0;
      |     ^~~~
C:\Users\Pease\Documents\codes\projects\main.cpp:3:12: error: expected ']' before 'auto'
    3 | int main()[
      |            ^
      |            ]
    4 |     auto result = (10 <=> 20) > 0;
      |     ~~~~    
C:\Users\Pease\Documents\codes\projects\main.cpp:5:10: error: 'cout' in namespace 'std' does not name a type
    5 |     std::cout << result << std::endl;
      |          ^~~~
In file included from C:\Users\Pease\Documents\codes\projects\main.cpp:1:
c:\msys64\mingw642\include\c++\12.1.0\iostream:61:18: note: 'std::cout' declared here
   61 |   extern ostream cout;          /// Linked to standard output
      |                  ^~~~
C:\Users\Pease\Documents\codes\projects\main.cpp:6:1: error: expected unqualified-id before ']' token
    6 | ]
      | ^

Build finished with error(s).
The terminal process terminated with exit code: -1.

Another example would be 'using' giving the error 'variable "using" is not a type name, when i try to enter "using namepsace std;" in another attempt.

Any help would be hugely appreciated. I have no idea what I am doing wrong, but it must be something!

1 Answers

Fix your code. Square brackets are not the way to create a function in C++, use curly brackets instead. <=> is not a valid operator, use !=.

Visual Studio Code is doing its job perfectly here.

Related