Why does Visual Studio underline std::getline in my C++ code?

0
0
Asked By MellowCactus47 On

Whenever I type std::getline in Visual Studio, getline gets a red underline and the program will not run. The same code works for a friend using another C++ editor. Here is the program:

#include

int main() {
std::string name;
std::cout < 15) {
std::cout << "Your name can't be over 15 characters";
} else {
std::cout << "Welcome " << name;
}

return 0;
}

Is there something I need to configure in Visual Studio, or is there another way to read a full line of text?

1 Answer

Answered By RavenToast6 On

You can keep writing std::cout, std::cin, std::string, and std::getline exactly as you have them. Adding using namespace std; would shorten the code, but it is generally better for beginners to keep the std:: prefix because it makes it clear where those names come from and avoids name conflicts.

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.