std::cin stops reading at space. Alternatives?

Started by
4 comments, last by Washu 19 years, 7 months ago
Recently, it came to my attention that std::cin does not read input past a space. What alternative is there?
.:<<-v0d[KA]->>:.
Advertisement
getline
Quote:Original post by C-Junkie
getline


Example?
.:<<-v0d[KA]->>:.
[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:

// 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-Junkie
[google]getline std::string
LMAO! The first result happens to be a post on gamedev.net.
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

In time the project grows, the ignorance of its devs it shows, with many a convoluted function, it plunges into deep compunction, the price of failure is high, Washu's mirth is nigh.

This topic is closed to new replies.

Advertisement