Re: why my code doesnt work
It is working. You haven't given it any reason to keep the command window open, so it doesn't. There are threads on this every week or so. Try running it from the command line or putting a breakpoint before your return.
Re: why my code doesnt work
Quote:
Originally Posted by
xxvoodooxx
#include <iostream>
#include <iomanip>
Code:
using std::cout;
int main()
{
char newline = '\n';
cout << newline;
cout << "\We\'ll make our escapes in sequence\", he said.";
cout << "\n\tThe program\'s over, it\'s time to make a beep beep.\a\a";
cout << newline;
return 0;
}
it just beep doesnt show the output line it flashes cmd then beep its gone.i tried f5 and ctrl f5
This code makes the following output in cmd window:
Code:
We'll make our escapes in sequence", he said.
The program's over, it's time to make a beep beep.
The reason you don't see it is the window closes just after return statement.
Try to set the breakpoint at the line with "return" and then press F5.
Or add system("pause"); statement.
Re: why my code doesnt work
the pause work..funny how my book doesnt write it in every exercise i do and it never tells me to write system("pause");
Re: why my code doesnt work
Quote:
Originally Posted by
xxvoodooxx
the pause work..funny how my book doesnt write it in every exercise i do and it never tells me to write system("pause");
Because that isn't technically the correct thing to do. It's a hack to make it easier for students to see outputs in their first few programs, that's all.
When you open Firefox, you don't expect the program to quit until you select "Quit" from the file menu. But if you open a command prompt and type "dir" (or "ls" in linux), you *do* expect the ls program to quit immediately after running without waiting.
You're creating a console app, which means your program is going to behave like dir, not like Firefox. Once it's over it exits. If the console was opened by the program start, then it will go away upon program end. (If you opened it yourself and manually ran the program it wouldn't disappear.)