string name;
cout << "Game Name: ";
cin >> name
string input question
Hello!
i recently finished my little project i was doing, but i have a minor problem. I ask the user for their fav video game, but if the game has multiple words, it counts that as 2 diff game names. Does anyone know how to make it so the user has put spaces in the games name and have it count as one string input??
ex:
You want to use std::getline():
jfl.
string name;cout << "Game Name: ";getline( cin, name );
jfl.
Just to add to jfl's post (if I remember correctly) getline leaves the delimiter in the stream, so you will have to strip it out if you want to capture more input after the call
yeah, this is what i added :D
std::cout << "enter name: ";std::cin >> std::ws;getline(std::cin, game_title);
Quote:Original post by CmpDev
Just to add to jfl's post (if I remember correctly) getline leaves the delimiter in the stream, so you will have to strip it out if you want to capture more input after the call
Nope. It is extracted and not stored. (This is usually the behaviour you want.)
Quote:Original post by ZahlmanQuote:Original post by CmpDev
Just to add to jfl's post (if I remember correctly) getline leaves the delimiter in the stream, so you will have to strip it out if you want to capture more input after the call
Nope. It is extracted and not stored. (This is usually the behaviour you want.)
Rrr that's correct yes. It was get I was thinking off.
Sorry
[History]CmpDev may be thinking of Visual c++ 6.0 which had incorrect behavior with std::getline, as laid out in this article.[/History]
Edit: apparently not!
Edit: apparently not!
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement