Kevin Duke Kevin Duke - 1 year ago 80
C++ Question

std::cin in input with spaces?

#include <string>

string input;
cin >> input;

The user wants to enter "Hello World". But
fails at the space between the two words. How can I make
take in the whole of
Hello World

I'm actually doing this with structs and
doesn't seem to work. Here's my code:

struct cd
string CDTitle[50];
string Artist[50];
int number_of_songs[50];

cin.getline(library.number_of_songs[libNumber], 250);

This yields an error. Any ideas?

Answer Source

You have to use cin.getline():

char input[100];
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download