when inputting character string values using cin>>, is it possible to put any spaces between words?
Printable View
when inputting character string values using cin>>, is it possible to put any spaces between words?
Yeah...try cin.getline()
Code:
#include <iostream>
using std::cout;
using std::cin;
using std::endl;
int main(void){
const int ARRAYLENGTH = 50;
char buff[ARRAYLENGTH];
cout << "Type something with spaces" << endl;
cin.getline(buff,ARRAYLENGTH-1);
cout << "You wrote " << buff << endl;
return 0;
}
Err...look above :)
I get a qualifier 'std' is not a class or namespace name error, whats wrong
Hmm...maybe your compiler is old....substitute
forCode:#include <iostream>
using std::cout;
using std::cin;
using std::endl;
If this works, great, but seriously consider a new compiler! There are loads free on the web for downloadCode:#include <iostream.h>