Whenever I type std::getline in my C++ file, Visual Studio shows a red underline and I can't run the program. The same code works for a friend using a different editor. I'm trying to read a name and check whether it is longer than 15 characters:
#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;
}
What do I need to change, and is there an alternative to getline?
2 Answers
You don't need an alternative to getline. It is the right tool for reading an entire line, including spaces. Also, writing std:: explicitly is normal C++ style; using namespace std; can shorten the code, but avoiding it prevents name conflicts and is a better habit as programs grow.
Your code should be inside a proper C++ project in Visual Studio, with the .cpp file added to that project. Visual Studio is organized around solutions and projects, so opening a standalone source file may leave IntelliSense or the compiler configuration incomplete. Creating a C++ console project and adding the file to it should resolve project-related errors.

Related Questions
How To: Running Codex CLI on Windows with Azure OpenAI
Set Wordpress Featured Image Using Javascript
How To Fix PHP Random Being The Same
Why no WebP Support with Wordpress
Replace Wordpress Cron With Linux Cron
Customize Yoast Canonical URL Programmatically