VERY strange problem using the function gets() 
Author Message
 VERY strange problem using the function gets()

I hope someone can help me.
Simply: if I type these lines...

...
cout << "Sentence1";
gets(str);
cout << "Sentence2";
...

I get the result:

<prompt for the input of the string>
Sentence1
Sentence2

Does someone know why MS Visual C++ executes the gets()
function before the first cout instruction?
Please help me because I'm going MAD!



Wed, 19 Jan 2005 00:24:42 GMT  
 VERY strange problem using the function gets()

Quote:
> I hope someone can help me.
> Simply: if I type these lines...

> ...
> cout << "Sentence1";
> gets(str);
> cout << "Sentence2";
> ...

> I get the result:

> <prompt for the input of the string>
> Sentence1
> Sentence2

> Does someone know why MS Visual C++ executes the gets()
> function before the first cout instruction?

Because you didn't flush the output stream.  I believe cout will flush
automatically when you cout << endl, but you didn't.  You need an explicit
cout.flush().

Also, DO NOT use gets.  It doesn't allow you to specify the size of the
buffer you hand it, so there's no way to prevent potential buffer overflows.
Since you're using cout, try to use cin instead.



Wed, 19 Jan 2005 01:43:14 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. VERY strange problem using the function gets()

2. strange problem occur while trying to access member function through static function

3. Getting time strange problem

4. Strange crash using virtual function with thirdy part library class

5. Strange problem with function call - Anyone?

6. Strange Problem using SQL statement in ISAPI Extension

7. Strange member function naming problem...

8. Strange virtual function problem, please help!

9. strange problem when using mscomm32.ocx

10. Getting dialog box color without using GetSysColor API function

11. Problem with getting values back from a function...

12. gets() function problem...

 

 
Powered by phpBB® Forum Software