Why is there a red squiggle in my c++ code (both in VS and in VScode) even tho it compiles?

Viewed 66

I reduced the problem to this small working code:

#include<iostream>

int main() {
    std::string s = "1";
    int i = stoi(s);
    return 0;
}

This code compiles without errors in VSCode with wsl linux, but stoi is underlined with red.

If I add

#include <string>

, then everything is good. But my school assignment doesn't allow to add any includes to the code.

The above code in Visual Studio doesn't compile at all, and the suggested quick fix is to use the string library, which, again, I am not allowed to use.

Apart from searching the internet endlessly, I tried the following:

  1. I suspected my compiler is not updated, so I updated g++ in wsl.

    Now g++ --version in WSL returns:

g++ (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0 Copyright (C) 2019 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

  1. I reset Visual Studio 2017 to its default settings.

  2. I updated Visual Studio 2017 to 2019.

  3. I updated Microsoft Visual C++.

  4. When I tried g++ --version in command prompt on Windows, it said g++ is not recognized as a command, so I downloaded MinGW and installed the compilers.

    Now g++ --version in Windows 10 returns:

g++ (MinGW.org GCC Build-2) 9.2.0 Copyright (C) 2019 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Does anybody know why my code doesn't compile in Visual Studio 2019 and why there is a red squiggle in VSCode? By the way I have the same issue with the getline() function, I suspect the same cause behind it.

0 Answers
Related