How put string with spaces in a array?

Hi, i'm difficults in put strings with spaces in arrays. Look my code:

#include <iostream>
#include <string>

using namespace std;

int main()
{
string aux;

cout << "Write: ";
cin >> aux;

cout << aux <<endl;

return 0;
}


I want enter with:

Write: lololo lalalala

output

lololo lalalala
thanks
But if i put a cout after getline not behave, for example:

#include <iostream>
#include <string>

using namespace std;

int main()
{
string aux, aux2;

cout <<"Write 1: ";
cin >> aux;
cout << "Write 2: ";
getline(cin, aux2);

cout << aux << " " <<aux2 << endl;

return 0;
}

I want enter with:

Write 1: lololo
Write 2: fsdafasd fdsafsdafasd fsdafdsa

output

lololo fsdafasd fdsafsdafasd fsdafdsa



Help me!
you can add an escape sequence...

replace
getline(cin, aux2);
with
getline(cin, aux2, '$');

until you hit $ then enter... it will copy whatever you type.

or...

cout <<"Write 1: ";
cin >> aux;
cout << "Write 2: ";
cin>> aux2;
Last edited on
Topic archived. No new replies allowed.