std::cin stops reading at space. Alternatives?
Recently, it came to my attention that std::cin does not read input past a space. What alternative is there?
[google] getline
okay, maybe a little easier:
getline, googled
okay maybe a little easier:
first webpage that comes up when googling getline
okay maybe a little easier:
What's that? you wanted one that uses std::string?
[google]getline std::string
....
okay, maybe a little easier:
getline, googled
okay maybe a little easier:
first webpage that comes up when googling getline
okay maybe a little easier:
// istream getline#include <iostream>using namespace std;int main () { char name[256], title[256]; cout << "Enter your name: "; cin.getline (name,256); cout << "Enter your favourite movie: "; cin.getline (title,256); cout << name << "'s favourite movie is " << title; return 0;}
What's that? you wanted one that uses std::string?
[google]getline std::string
....
Quote:Original post by C-JunkieLMAO! The first result happens to be a post on gamedev.net.
[google]getline std::string
Quote:Original post by v0dKA
Recently, it came to my attention that std::cin does not read input past a space. What alternative is there?
It's not that cin doesn't read whitespaces, it's that the >> operators are designed to not read whitespaces. Do as C_Junkie said.
[google] getline
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement