delaying screen output [was:can anyone help about this?]
hi guys, first of all i would like to say a "Hi" to all of u here since i'm new here, just registered here :WAVE:
yeah, my question is this:
i'm used to using the Borland Turbo C++ compiler. Now i have decided to switch to Visual C++.
But in Turbo i was used to inlcuding the library <conio.h> which allowed me to use functions like clrscr(); and getch();
when i used to code with Borland Turbo C++, i used to put the functions clrscr(); and getch(); at beginning and end, respectively. This was useful in the sense that when i click on the created .exe file, i could see the output...but without getch(); when i open the .exe file, the window just opens and closes in a fraction of a second, without allowing to see the output!
So any remedy to this those who are comfortable with Visual C++ ?
Thanks for ur time and attention!
Kind Regards!
[914 byte] By [
wakish] at [2007-11-11 6:53:35]

# 1 Re: delaying screen output [was:can anyone help about this?]
system("pause") is a good way to see your output. System is standard but pause is a dos command.
You do not need to clear the screen as new programs start in a new virtual dos box that is clear already. If you do need to clear it you will have to either print end lines or look deeper into the console functions (not part of c++ but different for each vendor).
jonnin at 2007-11-11 21:02:46 >

# 2 Re: delaying screen output [was:can anyone help about this?]
but these functions does not really do what a getch(); normally does with Borland Turbo C++
i get these:
1) when using the cin.get();
the output appears on the screen, then the cursor is on next line...waiting for me to type any key...Then when i press any key, the sentence "press any key to continue..." appears
I want this sentence to appear after the output directly..this is more sound!
2) with system("pause");
the sentence "press any key to continue ..." appears FIRST and when i press any key, the window closes instantly without me seeing the output :(
any other solutions dude?
wakish at 2007-11-11 21:03:52 >

# 3 Re: delaying screen output [was:can anyone help about this?]
int main()
{
cout << "hello world" << endl;
//optional 'cout.flush();' here --usually if you must do this you have a bug
system("pause");
return(0);
}
.. You are saying the pause message appears (press a key) yet you do not see "hello world" ?? If so you may have to flush .. (cout.flush();) But this should not be needed.
Microsoft has a version of getch -- its like __getch or some such, if you prefer. All the nonstandard stuff has two underscores - bunches of them.
If you run from inside visual studio, the environment will call your exectuable and then a dos pause, so you can see output without making code changes. Its only needed if you double click your app from the gui. If you simply open a command prompt and run your program, you will see output.
If all else fails execute with a "prog.exe >filename.txt" and you can have your output in a text file ...
Let me know whats going on ..
jonnin at 2007-11-11 21:04:56 >

# 4 Re: delaying screen output [was:can anyone help about this?]
hey dude when i do it like this, it works perfect!!!
void main()
{
cout << "\nHi! This is a test line\n";
cout.flush();
system("pause");
}
Hey tnx dude!! that was exactly what i wanted. U r the 1st person to have answered to what i really wanted. tnx!
btw can u explain what's the mechanism of the cout.flush(); dude..
tnx!
wakish at 2007-11-11 21:05:50 >

# 5 Re: delaying screen output [was:can anyone help about this?]
btw dude how clearscreen be used in Visual C++
in borlan turbo clrscr(); works perfect, but in visual it's not same..
wakish at 2007-11-11 21:06:50 >

# 6 Re: delaying screen output [was:can anyone help about this?]
I dont know clrscr for visual but im sure its in there somewhere.
Flush tells the low level I/O stuff to force the OS to put the data stream 'out'. This keeps the OS from buffering the output until some buffer is full or the cpu goes idle or whatever else it wants to do to keep you from seeing your output. It is available on any file (cout is a special file that is pointed to the screen instead of the disk).
jonnin at 2007-11-11 21:07:49 >

# 7 Re: delaying screen output [was:can anyone help about this?]
btw i have not yet find a way for the clearscreen...Danny can u plz help?
tnx!
wakish at 2007-11-11 21:08:59 >

# 8 Re: delaying screen output [was:can anyone help about this?]
I luv the Borland C++ DOS mode compiler. And i think that you dont have to write anything likke pause or system(), because every windows dos mode proragm stops without exiting. Let me try it. and then I post the correct answer.
NabeeL at 2007-11-11 21:09:51 >

# 9 Re: delaying screen output [was:can anyone help about this?]
for the clrscr(), look the 2nd reply of Jonnin.
NabeeL at 2007-11-11 21:10:55 >

# 10 Re: delaying screen output [was:can anyone help about this?]
#include <stdio.h>
int main(int argc, char* argv[])
{
printf("Hello World!\n");
return 0;
}
this code starts in a new DOS box so screen is clear at the beginning.
and the code of VC++ does not exit automtically, it says at the end of execution,
" Press any key to continue"
and after that Exits. :)
I think ur problem solved.
NabeeL at 2007-11-11 21:11:56 >

# 11 Re: delaying screen output [was:can anyone help about this?]
It wont stop at the end of the program if your double click the exe. It WILL if you run from inside visual because visual calls 'pause' for you!
The new VDM is always clear but sometimes you want to clear screen inside the program after a few pages of output.
jonnin at 2007-11-11 21:12:59 >

# 12 Re: delaying screen output [was:can anyone help about this?]
yeah exaactly jonnin!
when u use the exe file outside the IDE and if ur program is a menu-driven one, you would want to clearscreen internally at a certain point.
so how to clearscreen, what code to write for vc++??
[with botland i know it's simply clrscr(); ]
Danny perhaps u can help a bit here dude? :confused:
wakish at 2007-11-11 21:13:57 >

# 13 Re: delaying screen output [was:can anyone help about this?]
the simplest ay to clear the screen is by outputing a sequence of say 24 new line characters:
cout<<'\n'<<'\n'<<'\n'<<'\n'<<'\n'<<'\n'<<'\n'<<endl;
Danny at 2007-11-11 21:14:59 >

# 14 Re: delaying screen output [was:can anyone help about this?]
that seem logical but it can be different on different screen...
is there any other way to do it, like calling a function or making our own header to clearscreen dude?
tnx for ur kind attention!
wakish at 2007-11-11 21:15:59 >

# 15 Re: delaying screen output [was:can anyone help about this?]
there are dozens of ways to do it, but they're not protable. cout<<'\n' is portable and rather efficient.
Danny at 2007-11-11 21:17:03 >

# 16 Re: delaying screen output [was:can anyone help about this?]
system("cls"); -- let dos do the work for you?
jonnin at 2007-11-11 21:18:07 >

# 17 Re: delaying screen output [was:can anyone help about this?]
ok..tnx..i'll try it out!
btw the function system is in which header file? <cstdlib>?
wakish at 2007-11-11 21:19:00 >
