I am using Turbo C++ 3.0 (that is what we have been told to use by our school teacher)
I was just given a basic program by my teacher to try a hand on
What happens is that when i run the program(after proper error-free compilation)a DOS screen is displayed for a split-second and then nothing happens
It looks as if the text to be outputed is displayed but the screen doesn't stay on
Please help!!
Help with C++.. i wrote out a basic program and compiled it(without any error) but it doesn't display anything
After creation of the .exe file, don't run the file from Windows, instead, go to the command prompt -%26gt; Start -%26gt; Run -%26gt; cmd.exe, and then go to the location of the .exe file and type the name and run it, that way the command prompt window won't disappear.
Reply:If i could able to view the code gives a better idea
Reply:start dos using run type cmd
u can add getch(); in last line of program
Reply:%26gt;%26gt; I am using Turbo C++ 3.0 (that is what we have been told to use by our school teacher)
Please tell your teacher that C++ has changed significantly with ANSI 99 revisions. Unless he intends to teach antiquated code, he should use a modern compiler like gcc/MinGW, or Visual C++. There is a free express edition of Visual C++ that he can have everyone install. And he can learn some modern C++ himself too.
%26gt;%26gt; DOS screen is displayed for a split-second and then nothing happens
It's not a DOS screen. It's a console window. Your program runs in a console window, but then once it is over, the console window closes (because it is no longer needed). The correct way is to manually open up a console window.
Look at Tamim's and StarChaser's answers for how to do so. For a guide on how to open up a command window. Google for Windows XP console commands, and more specifically how to use "cd". cd to your executable directory. Type in the name of the executable.
%26gt;%26gt; #include%26lt;iostream.h%26gt;
In modern C++ it is #include %26lt;iostream%26gt;
%26gt;%26gt; void main()
Incorrect. It is int main() . Required by the standard.
%26gt;%26gt; cout%26lt;%26lt;"Hello World";
std::cout %26lt;%26lt; "Hello world";
Hence your program should be something like
#include %26lt;iostream%26gt;
using namespace std;
int main()
{
cout %26lt;%26lt; "Hello, world";
return 0;
}
Reply:Well, this is what happens
Your program runs, does its thing and end. Windows terminate the session and close the window running your program.
This happens every time you run a command (try running ipconfig from Start -%26gt; run... it will open a CMD window and zaps it again).
So, what you should do is to open a CMD window [Start-%26gt; run -%26gt; cmd] and run your program from there by typing the name of the executable that TC builds.
Happy programing
Reply:don't press any key when excute your program
or check if write in the end of code
(return 0)
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment