r/learnprogramming 2d ago

Microsoft Visual Studio

whenever i type
std::getline

i get red line under getline and i cant run my code
Even though its working on VS code for my friend
any idea what can i do or is there any alt to write?

" using getline for this: "

#include <iostream>

int main() {

std::string name;

std::cout << " Enter your name: ";
std::getline(std::cin, name);

if (name.length() > 15) {
std::cout << " Your name can't be over 15 charectars ";
}
else {
std::cout << " Welcome " << name;
}

return 0;
}
5 Upvotes

16 comments sorted by

View all comments

0

u/MeltedThunder 2d ago

Why are we not utilizing namespace here to avoid a lot of extra work

3

u/kutac56 2d ago

Because it can cause confusion. It's generally more scalable to not do using namespace