Sign in to follow this  

std::cin stops reading at space. Alternatives?

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

[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 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

This topic is 4838 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this