-1

I was setting up VS Code to program in c++, but quickly confronted the problem: identifier "cout" is undefined.

#include<iostream>
using namespace std;

int main() {
    cout << 1; // identifier "cout" is undefined C/C++(20)
    return 0;
}

But I ctrl + click cout, it successfully goto iostream library.

When modified as follows, it got namespace "std" has no member "cout":

#include<iostream>

int main() {
    std::cout << 1; // namespace "std" has no member "cout" C/C++(135)
    return 0;
}

By the way, the problem occurred after I reinstalled the system. There wasn't such problem before. All the settings are synchronized via my account.

Additional screenshots:

when ctrl+click cout

C_Cpp.default.includePath

  • 2
    Is it problem with Intellisense or compiler? – Yksisarvinen Aug 18 '23 at 09:48
  • Show your .json configuration files. – πάντα ῥεῖ Aug 18 '23 at 09:50
  • 3
    Why do you have both tdmgcc and mingw64 in include paths? That's looking for trouble. – HolyBlackCat Aug 18 '23 at 09:50
  • 2
    On a side note, I recommend following: Uninstall your compiler(s), uninstall/disable the stock microsoft intellisense, use [MSYS2](https://stackoverflow.com/q/30069830/2752075) to install both GCC and Clangd, install the Clangd plugin in VSCode (and configure it to use the Clangd installed from MSYS2). You'll then have a sane code completion that works out of the box with no configuration. – HolyBlackCat Aug 18 '23 at 09:51
  • Oh, one more thing, it still can compile: `cd "d:\Desktop\" ; if ($?) { g++ -std=c++11 1.cpp -o 1 } ; if ($?) { .\1 }` which output 1. – Skylar Dawn Aug 18 '23 at 09:53
  • Using `#` instead of `//` to make comments in code is not going to work unless your compiler has a very unusual extension. – Ted Lyngmo Aug 18 '23 at 09:56
  • 3
    VSCode isn't beginner-friendly. I recommend a C++ IDE, e.g. Visual Studio, CLion, Eclipse CDT. There are so many questions about VSCode because the configuration is too complex for beginners. – jabaa Aug 18 '23 at 09:59

1 Answers1

0

Might be an issue with intellisense and VSCode. Try searching VSCode extensions for C++ code support and intellisense and then reboot.

Cornel
  • 180
  • 2
  • 4
  • 13