How to read spaces in a string

Hi, im trying to read a whole sentence. Im trying this:


1
2
3
4
5
6
7
8
9
10
11
12
13
struct ingresos{
	float monto;
	string concepto,rfc;
}ingreso[20];

void capturaIngresos(int pos){

        cout<<endl;
        cout <<"Concepto: ";
        getline(cin,ingreso[pos].concepto);
        cout <<"RFC: ";
        cin>>ingreso[pos].rfc;
 }


At trying to read "Concepto", it jumps to the next line.

Thanks in advance
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
void capturaIngresos(int pos){

        cout<<endl;
        cout <<"Concepto: ";

        //getline(cin,ingreso[pos].concepto); // unformatted input

        // skip over the trailing white space left behind by the formatted input
        // see: http://www.cplusplus.com/reference/istream/ws/
        // for more information: http://www.cplusplus.com/forum/general/69685/#msg372532
        getline( cin >> ws, ingreso[pos].concepto );

        cout <<"RFC: ";
        cin>>ingreso[pos].rfc; // formatted input
 }
thanks a lot =D


Topic archived. No new replies allowed.