-3

I am receiving the following error:

error: expected ';' at end of declaration
    int hello {8};
             ^
             ;

1 error generated.

I just bought this computer and downloaded VS Code. I ran xcode-select --install in the terminal. I have the XCode developer tools. I can run the C++ program, but not with this form of variable initialization.

#include <iostream>

int main() {
    int hello {8};
    std::cout << "hello world" << std::endl;
    return 0;
}

Other things I tried:

  • Uninstalled xcode and installed, did not work
  • Enabled c++20 cppstandard in vscode, did not work
  • Uninstalled vscode and installed, did not work
Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
Alec
  • 1
  • 1
  • Welcome to Stack Overflow. Please include your code. – ewokx Aug 23 '23 at 02:10
  • What happens if you compile from the command line? `clang -std=c++20 file.cpp -o file`? There are two different places to set the standard in VSCode for two different purposes. Did you change both? – Retired Ninja Aug 23 '23 at 02:12
  • @Retired Ninja, I tried to enter that command into the terminal and recieved and error "error: linker command failed with exit code 1 (use -v to see invocation)" – Alec Aug 23 '23 at 02:16
  • @Retired Ninja, I only updated the "Cpp Standard" inside "Extensions" from the settings. From what I understood, installing xcode should give me the command line tools but I don't know what else I need from there. – Alec Aug 23 '23 at 02:17
  • 3
    `Enabled c++20 cppstandard in vscode`, `updated the "Cpp Standard" inside "Extensions" from the setting`, hence you updated only IntelliSense config, you should update tasks too. – 273K Aug 23 '23 at 02:57
  • 4
    Read and understand this documentation: [https://code.visualstudio.com/docs/cpp/config-clang-mac](https://code.visualstudio.com/docs/cpp/config-clang-mac) You will need to edit both `tasks.json` and `c_cpp_properties.json` to set the standard. The documentation recommends c++17 and shows the two places you need to change: `-std=c++17` in tasks.json and `"cppStandard": "c++17",` in c_cpp_properties.json – drescherjm Aug 23 '23 at 03:05
  • Both tasks.json and c_cpp_properties.json have been updated. No resolution. Even tried copying entire tasks.json as instructed in the the document. – Alec Aug 23 '23 at 03:42
  • show what you did in your tasks.json. maybe you did it wrong. – starball Aug 23 '23 at 06:08
  • 1
    @Alec To know what you did wrong, we have to see what you did, not read a description of what you think you did. This seems obvious. – john Aug 23 '23 at 06:26
  • 1
    @RetiredNinja's command needs to be `clang++` rather than `clang` which is why you get a linker error – Alan Birtles Aug 23 '23 at 06:33
  • Make sure you are not using code-runner. – drescherjm Aug 23 '23 at 14:03

0 Answers0