Jan 13, 2012 at 7:30pm Jan 13, 2012 at 7:30pm UTC
Hi,
my problem: cout << "number:" << flush;
cin >> Nr;
if I don't comment this lines I can't read sentence One! Read something about flush, but I don't know how to use it properly.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
#include <cstdlib>
#include <iostream>
using namespace std;
/*
*
*/
int main() {
char One[256], Two[256];
int Nr;
// cout << "number:" << flush;
// cin >> Nr;
//
cout << "sentence One: " ;
cin.getline (One,256);
cout << "sentence Two: " ;
cin.getline (Two,256);
cout << One << " " << Two; // << " " << Nr << endl;
}
kind regards
Last edited on Jan 13, 2012 at 7:31pm Jan 13, 2012 at 7:31pm UTC
Jan 13, 2012 at 7:37pm Jan 13, 2012 at 7:37pm UTC
the >> operator doesn't remove the newline from the buffer so when you call getline(One,256) it finds the newline in the buffer and returns immediately. To remedy this you could use cin.ignore(256,'\n'); after the 'cin >> Nr;'