Read string with c++ spaces

Asked

Viewed 305 times

0

I need to read a string considering the spaces in c++. Type like this:

string frase;
std::cin >> frase;

It seems trite, but I can’t seem to solve it. Grateful, from now on.

  • Does this help you? https://answall.com/questions/255847/como-ler-uma-string-com-espa%C3%A7o-em-c-dentro-de-uma-fun%C3%A7%C3%A3o

1 answer

3


You, can use the getline function(), getline(cin, frase);, will consider the spaces it will stop reading until it breaks a line.

  • You can have a look at the documentation : http://www.cplusplus.com/reference/string/string/getline/

  • 1

    Thank you very much! It worked here.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.