Jump to content
  • Advertisement
Sign in to follow this  
RogerThat123

C++ getline()

This topic is 3093 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

        
        SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), WHITE);
	cout << "Enter the customer name (FIRST LAST): ";
	SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), LIGHTGREY);
	getline(cin,name);

when this line is executed, it doesnt even let me enter the name, it outputs the cout line and continues on, like its failing for some reason. It works if i put it in my main function, but in another function in a different cpp file a wierd things happen. Any idea why this might happen?

Share this post


Link to post
Share on other sites
Advertisement
There's probably something left in the input buffer. Try adding this before the getline and see if it works:

std::cin.ignore(std::cin.rdbuf()->in_avail());

(basically, it ignores everything that's left over in the input buffer)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!