| | |
Newbie Question (Hello World)
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: May 2005
Posts: 4
Reputation:
Solved Threads: 0
I started to learn C++ few days ago. When I Run a program it show a console window for a moment then return to IDE. I even couldn't see the output.
for example followig Hello World Program
what should I add in this code (infact every code) to stop this problem. I tried to fix it myself by adding cin.ignore(); at the end of the program. But this doesn't workout where program requires the input from user.
for example followig Hello World Program
C++ Syntax (Toggle Plain Text)
// a small C++ program #include <iostream> using namespace std; int main() { cout << "Hello, world!" << endl; }
what should I add in this code (infact every code) to stop this problem. I tried to fix it myself by adding cin.ignore(); at the end of the program. But this doesn't workout where program requires the input from user.
Last edited by ehsen; Sep 3rd, 2007 at 2:56 am.
i am not in front of windows, so i can't test the advise::
try inserting system("pause"); and in the beginning <include> <cstdlib>
-i am not sure about which library to include...i am sure about the system command
another way would be to declare a dummy variable and read it at the end of the programm....
try inserting system("pause"); and in the beginning <include> <cstdlib>
-i am not sure about which library to include...i am sure about the system command
another way would be to declare a dummy variable and read it at the end of the programm....
I would not recommend using as it is not portable between various operating systems...try something like at the end instead...
C++ Syntax (Toggle Plain Text)
system("pause");
C++ Syntax (Toggle Plain Text)
cin.get();
•
•
•
•
I tried to fix it myself by adding cin.ignore(); at the end of the program. But this doesn't workout where program requires the input from user.
C++ Syntax (Toggle Plain Text)
#include <iostream> using namespace std; void BlockPause() { // Set the state so cin can read. cin.clear(); // Clear everything in the stream cin.sync(); // Do the pause cin.ignore(); } int main() { // All of your other code goes here // Pause at the end with BlockPause cout<<"Press enter to continue..."; BlockPause(); return 0; }
The truth does not change according to our ability to stomach it.
No you really shouldn't. It's non-portable.
Better would be to learn how to execute a command-line program from the command line.
And please use [code][/code] tags.
Better would be to learn how to execute a command-line program from the command line.
And please use [code][/code] tags.
Last edited by Dave Sinkula; Sep 3rd, 2007 at 4:03 pm.
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
![]() |
Similar Threads
- a question about inherite classes (Java)
- Newbie Question - How to generate a link (PHP)
- C help to newbie (C)
- How can i connect my win laptop with my mini? (OS X)
- Newbie Question - Hiding php extension (PHP)
- Stupid Newbie Question (C)
- AGP Aperture Size Question (Windows NT / 2000 / XP)
- Uber-N00B question (C++)
- How to network two Win98 machines (Networking Hardware Configuration)
Other Threads in the C++ Forum
- Previous Thread: for rookie C++ (template) programmers
- Next Thread: SIP Gateway
| Thread Tools | Search this Thread |
api array based beginner binary bitmap c++ c/c++ calculator char char* class classes coding compile compiler console conversion count data database delete desktop developer directshow dll dynamic dynamiccharacterarray email encryption error file forms fstream function functions game getline google graph homeworkhelper iamthwee ifstream input int integer lib linkedlist linker linux list loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference return rpg sorting string strings struct template templates test text tree unix url vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






