cin and spaces


S

Samuele Armondi

Hi,
I'm trying to use cin to capture some input from the console, but it always
seems to consider a space as the end of the string. I tried to use
cin.getline() but it only works for char arrays, and I would rather use
strings. At the moment, I'm using getline to read the input into a char
array and I'm then making a string out of it. Is there a more elegant way of
doing this?
Thanks in advance,
S. Armondi
 
Ad

Advertisements

V

Victor Bazarov

Samuele Armondi said:
I'm trying to use cin to capture some input from the console, but it always
seems to consider a space as the end of the string. I tried to use
cin.getline() but it only works for char arrays, and I would rather use
strings. At the moment, I'm using getline to read the input into a char
array and I'm then making a string out of it. Is there a more elegant way of
doing this?

std::getline(std::cin, somestring);

V
 
Ad

Advertisements


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top