![]() |
Need help getting started
Okay, I just started a tutorial online, http://www.cprogramming.com. I started it, and compiled and ran. Then nothing happened. I used the same code they used. I don't understand why nothing is happening, I would expect some sort of window to pop up or something. Here's the code so you don't have to go look for it:
Quote:
|
what compiler do you use?
|
Please read the "How to Post a Question" thread. Information is key; you need to think about it. Also, may as well read the forum's faq/rules while you're at it, just for future reference. Having a window appear only long enough to get a flash of it is perfectly normal, if the window belongs to the app. If the window belongs to YOU (because you opened a cmd window and launched your program from there), then it will persist. This is an exceedingly common question and has been answered several times on the forum (which is why we have a search button, to reduce the pain of repeating ourselves). At any rate, the quick solution, IF that's the problem (your informative description falls very short), is to ask for user input at the very end. That has the effect of keeping your program from finishing (and closing its window) before your eyeballs can glom onto things.
Read those thangys. Your operating system, platform, exact error messages, succinct description, are almost ALWAYS needed. We had a mind reader but he was taxed once too often and is now in the looney bin. |
Besides all of those things that DaWei said, change
:
return 1;:
return 0; |
If you use the devc++ compiler, add the folowing code at the end of program, instead of return 1:
char response; cin>>response; and that should do it |
hervens48: cin.get(); waits for user to press enter before continuing, which is basically the same thing you're telling him to do. Also, you wouldn't replace return 1; with this code. It's a bad habbit to leave out the termination of the program properly.
|
There's little point wasting a variable, 'response', when you're going to deep-six the input. The only purpose of the input is to make the program wait for a user signal. While a C++ compiler should provide a return for you, if you can't be sure (about your compiler and its compliance), how much does it cost to type, "return 0".
|
I do use Dev-C++ complier. Sorry, I was going to put that in, but I got distracted from the computer and forgot to add it, sorry. I tried replacing return 1; with what hervens said, same thing. I have the cin.get() on there, so I don't understand why a window doesn't pop up or whatever? When I go to the exe file, I double click on it, and the waiting cursor appears for like .2 seconds. Does this mean it is working, its just going on and off the screen too fast for eyes to pick up.
|
Try clearing the stream by using 'cin.clear();' before 'cin.get();'.
EDIT: Make that: cin.sync(); :) |
i tried both the the cin.clear and cin.sync, and neither worked. They both did the same thing, flash of waiting cursor then back to the normal pointer cursor.
|
| All times are GMT -5. The time now is 7:58 AM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC