problem with input of strings

my cin.getline doesnt let me enter the variable it takes them as null and procedess to cout and finally getch(); what should i do to correct it.
i use code blocks gcc compiler

1
2
3
4
  char comp[50];
  cin.getline(comp,50);
  cout<<endl<<comp;
  getch();


i have also tried the strings library ( used string data type ) and also tried some work arounds still it didnt work.

1
2
3
4
char comp[50]<<endl;
cin>>comp;//this piece of code takes in the string but terminates
          //at white spaces         
cout<<endl<<comp;


same over here...

1
2
3
4
string comp<<endl;
cin>>comp;//this piece of code takes in the string but terminates
          //at white spaces         
cout<<endl<<comp;
Last edited on
Is there by any means some other statement like std::cin >> /*...*/ before?
If so: http://stackoverflow.com/a/21567292
Topic archived. No new replies allowed.