Reputation: 584
I am currently using 'Digital Mars C++' as I needed Turbo C++ like Syntax and 32-bit exe build so that's the reason.
Now my problem that I am facing is that when I write the code below,
#include <iostream.h>
#include <stdio.h>
int main()
{
char n[30];
cout << "Enter Name: ";
gets(n);
return 0;
}
Then I save this file then I save this file as test.cpp
.
Then I opened my command prompt and typed dmc test.cpp
.
Now as I got a compiled file the exe file test.exe
, now when I run it it's first asking for input then it displays a message Enter Name:
.
Please help me with this problem it is really necessary.
NOTE :
when I use printf instead of cout it works fine.
and when I replace my statement
cout << " Enter Name: ";
with
cout << " Enter Name: " << endl
then also i get my message and then asks input.
Please do not suggest me of using the GCC compiler.
And I would be glad if you direct me where to make changes in my stdio.h file to get rectified gets function to work properly or any such other header file which is related to fixing this error.
Upvotes: 0
Views: 55
Reputation: 584
You can Add this code,
cout << flush;
just before using cout << "Some Statement";
or
In direct approach you can do this cout << " Some Statement" << flush;
then use gets()
with ease.
Upvotes: 1