Programming Forums
User Name Password Register
 

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

Reply
 
Thread Tools Display Modes
Old May 17th, 2006, 9:28 PM   #1
proudnerd
Newbie
 
Join Date: May 2006
Posts: 21
Rep Power: 0 proudnerd is on a distinguished road
Beginner Problem

I just started programming in C++ (I gave up PHP because I realized that web programming isn't for me) and I have a problem already. There are errors when I try to compile my program. If you're going to tell me to search, well, I already did. Anyways, here's my very basic code:

#include <iostream>
#include <string>
using namespace std;
int main()
{
    string name = "Spencer";
    cout << name;
}
proudnerd is offline   Reply With Quote
Old May 17th, 2006, 9:31 PM   #2
Jimbo
Battle Programmer
 
Jimbo's Avatar
 
Join Date: Feb 2006
Location: Bellevue, WA, USA
Posts: 770
Rep Power: 3 Jimbo is on a distinguished road
What are your errors? I'm not sure if DaWei's crystal ball is back to operational status yet...
Jimbo is offline   Reply With Quote
Old May 17th, 2006, 9:42 PM   #3
proudnerd
Newbie
 
Join Date: May 2006
Posts: 21
Rep Power: 0 proudnerd is on a distinguished road
If you've ever used Dev-C++, there's four tabs at the bottom. Under the one titled "Linker" there's a big long list of errors.
proudnerd is offline   Reply With Quote
Old May 17th, 2006, 10:53 PM   #4
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
It isn't back, but I called the mechanic and got a run-down over the phone. One thing is that you've declared main as returning an int, which is correct, but then you don't return anything. Some compilers will just return trash, some will bitch and throw errors. Handle that, first. Jim's point, incidentally, is that if you see errors, and wish to ask about them, it would be nice to mention them explicitly and accurately. Silly as it seems, they're telling YOU something, and you're telling US nothing.
__________________
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 17th, 2006, 11:00 PM   #5
proudnerd
Newbie
 
Join Date: May 2006
Posts: 21
Rep Power: 0 proudnerd is on a distinguished road
Well, I tried a new compiler (MinGW) and that same code worked perfectly. Sorry that I didn't name the errors, but there were so many of them (I don't know how that's possible, it's such a small program). Anyways, should I start using "return 0;" just incase?
proudnerd is offline   Reply With Quote
Old May 17th, 2006, 11:02 PM   #6
ReggaetonKing
Sexy Programmer
 
ReggaetonKing's Avatar
 
Join Date: Nov 2005
Location: New Jersey
Posts: 891
Rep Power: 4 ReggaetonKing is on a distinguished road
Send a message via AIM to ReggaetonKing
would help...
__________________
I would love to change the world, but they won't give me the source code!
ReggaetonKing is offline   Reply With Quote
Old May 17th, 2006, 11:04 PM   #7
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
You shouldn't return 0 "just incase." You need to return 0 in order for the program to properly terminate(I've heard). It's such a simple thing to do, so why not add it?
__________________

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 17th, 2006, 11:16 PM   #8
proudnerd
Newbie
 
Join Date: May 2006
Posts: 21
Rep Power: 0 proudnerd is on a distinguished road
Actually jayme, I'm almost positive some compilers automatically do it. But you're right, it's such a small thing, and it's good practice anyway, so I might as well do it.
proudnerd is offline   Reply With Quote
Old May 17th, 2006, 11:33 PM   #9
ReggaetonKing
Sexy Programmer
 
ReggaetonKing's Avatar
 
Join Date: Nov 2005
Location: New Jersey
Posts: 891
Rep Power: 4 ReggaetonKing is on a distinguished road
Send a message via AIM to ReggaetonKing
A programmer should NOT rely on the compiler to do all the work for him/her. A compiler just translates the language into native or interpreted code* It's not a matter of good programming practice but just common programming sense.

*depends what programming language it is.
__________________
I would love to change the world, but they won't give me the source code!
ReggaetonKing is offline   Reply With Quote
Old May 17th, 2006, 11:35 PM   #10
proudnerd
Newbie
 
Join Date: May 2006
Posts: 21
Rep Power: 0 proudnerd is on a distinguished road
Yeah, I just realised that. I'm going to make a habit out of putting "return 0;" at the end of my programs.
proudnerd 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 3:55 AM.

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