Can't sync input and output streams... 
Author Message
 Can't sync input and output streams...

That is the problem:

cout.sync_with_stdio();
cout << "Sentence1 ";
cin.getline(str, LENGHT);
cout << "Sentence2 ";
...
cout << "Sentence3 ";
cin.getline(str, LENGHT); //this instruction is jumped!
cout << "Sentence4 ";
...

Why sentence2 waits for the input of str while sentence4
does not? (ie: the second getline is not executed).



Fri, 21 Jan 2005 23:20:41 GMT  
 Can't sync input and output streams...
I see two possible reasons.

1. The user actually types LENGHT or more characters before hitting
Enter. First getline retrieves first LENGHT-1 of them, leaving the rest
in the input buffer. Second getline just retrieves the rest. It does not
wait for the input because unprocessed input is already waiting in the
buffer.

2. There is something wrong in the code you have thoughtfully replaced
with ellipsis. Probably another input function that leaves unprocessed
carriage return in the buffer.
--
With best wishes,
    Igor Tandetnik

"For every complex problem, there is a solution that is simple, neat,
and wrong." H.L. Mencken


Quote:
> That is the problem:

> cout.sync_with_stdio();
> cout << "Sentence1 ";
> cin.getline(str, LENGHT);
> cout << "Sentence2 ";
> ...
> cout << "Sentence3 ";
> cin.getline(str, LENGHT); //this instruction is jumped!
> cout << "Sentence4 ";
> ...

> Why sentence2 waits for the input of str while sentence4
> does not? (ie: the second getline is not executed).



Sat, 22 Jan 2005 04:06:43 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Unable to sync input and output streams

2. Programming REXEC() with input and output streams

3. Difficulty with input/output streams

4. input, output, input/output parameters?????

5. Multiplexing 'select' sync I/O

6. Need FIX: std::wofstream Can't Output After DBCS Character Is Output (Q274012)

7. How to clear input stream in ANSI C?

8. c file (stream) input buffer problem help PLEASE!

9. flushing the standard input stream (newb question)

10. ANN: Numeric input from file streams

11. clearing input streams

12. state of input stream after bad scanf ?5

 

 
Powered by phpBB® Forum Software