Jump to content
  • Advertisement
Sign in to follow this  
v0dKA

std::cin stops reading at space. Alternatives?

This topic is 5084 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 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
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!