Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old May 29th, 2006, 6:58 PM   #1
g2k556
Newbie
 
Join Date: May 2006
Posts: 7
Rep Power: 0 g2k556 is on a distinguished road
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:
#include <iostream>

using namespace std;

int main()
{
cout<<"HEY, you, I'm alive! Oh, and Hello World!\n";
cin.get();

return 1;
}
g2k556 is offline   Reply With Quote
Old May 29th, 2006, 7:05 PM   #2
hervens48
Programmer
 
Join Date: Apr 2006
Location: Montreal, Canada
Posts: 95
Rep Power: 3 hervens48 is on a distinguished road
Send a message via AIM to hervens48 Send a message via MSN to hervens48
what compiler do you use?
hervens48 is offline   Reply With Quote
Old May 29th, 2006, 7:44 PM   #3
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
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.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old May 29th, 2006, 8:07 PM   #4
Prm753
Professional Programmer
 
Prm753's Avatar
 
Join Date: Oct 2005
Location: United States
Posts: 447
Rep Power: 4 Prm753 is on a distinguished road
Send a message via AIM to Prm753 Send a message via MSN to Prm753
Besides all of those things that DaWei said, change
return 1;
to
return 0;
1 usually means that an error has occurred, 0 does not. 0 is generally what you end a program with.
__________________
The world's first athletic computer geek!
The home of PrProgramsStudios
How not to post a question: <-- Please don't reply
Prm753 is offline   Reply With Quote
Old May 29th, 2006, 8:24 PM   #5
hervens48
Programmer
 
Join Date: Apr 2006
Location: Montreal, Canada
Posts: 95
Rep Power: 3 hervens48 is on a distinguished road
Send a message via AIM to hervens48 Send a message via MSN to hervens48
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 is offline   Reply With Quote
Old May 29th, 2006, 8:38 PM   #6
jayme
Professional Programmer
 
jayme's Avatar
 
Join Date: Nov 2005
Location: Canada
Posts: 495
Rep Power: 0 jayme is an unknown quantity at this point
Send a message via MSN to jayme
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.
__________________

Quote:
Originally Posted by Mohamed Jihad
Durka durka!
Due to incorrect calculations during the middle ages, our calendar actually begins a few years after Jesus' birth. Thus the real 6/6/6 happened a few years back. The world already ended and you missed it.

Download Code::Blocks now!
jayme is offline   Reply With Quote
Old May 29th, 2006, 8:43 PM   #7
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
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".
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old May 29th, 2006, 10:02 PM   #8
g2k556
Newbie
 
Join Date: May 2006
Posts: 7
Rep Power: 0 g2k556 is on a distinguished road
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.
g2k556 is offline   Reply With Quote
Old May 29th, 2006, 10:23 PM   #9
Cache
Hobbyist
 
Join Date: Sep 2005
Posts: 266
Rep Power: 4 Cache is on a distinguished road
Try clearing the stream by using 'cin.clear();' before 'cin.get();'.

EDIT: Make that: cin.sync();
Cache is offline   Reply With Quote
Old May 30th, 2006, 4:36 PM   #10
g2k556
Newbie
 
Join Date: May 2006
Posts: 7
Rep Power: 0 g2k556 is on a distinguished road
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.
g2k556 is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 5:59 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC