• Advertisement
Sign in to follow this  

std::cin stops reading at space. Alternatives?

This topic is 4907 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

Recently, it came to my attention that std::cin does not read input past a space. What alternative is there?

Share this post


Link to post
Share on other sites
Advertisement
[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

....

Share this post


Link to post
Share on other sites
Quote:
Original post by C-Junkie
[google]getline std::string
LMAO! The first result happens to be a post on gamedev.net.

Share this post


Link to post
Share on other sites
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

Share this post


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

  • Advertisement