[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

problems with cin.getline && scanf or others



hi, i'm trying 2 do some home work with linux and i can't because i need
to input a string with spaces and it doesn't work, here's a short thing
as an example:

#include <iostream.h>

int main ()
{
	int i;
	char words[30];
	cin >> i;
	cin.getline(words, sizeof(words));
        cout << words << endl;
	cout << i;
}

the output of this would be after compilation:

$ ./test
343


343

so i am not able to input that text, on the other hand if i had:

#include <iostream.h>

int main ()
{
        int i;
	char words[30], awords[30];
	cin >> i;
	cin.getline(words, sizeof(words));
	cin.getline(awords, sizeof(awords));
	cout << words << endl;
	cout << awords << endl;
}

i can do an input for both getlines and the output would be as expected.
I'dlike 2 add that the same happens with scanf or gets.

i'm running sid with a compiled 2.4.3 kernel 
TIA



Reply to: