![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: May 2006
Posts: 21
Rep Power: 0
![]() |
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;
} |
|
|
|
|
|
#2 |
|
Battle Programmer
Join Date: Feb 2006
Location: Bellevue, WA, USA
Posts: 770
Rep Power: 3
![]() |
What are your errors? I'm not sure if DaWei's crystal ball is back to operational status yet...
|
|
|
|
|
|
#3 |
|
Newbie
Join Date: May 2006
Posts: 21
Rep Power: 0
![]() |
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.
|
|
|
|
|
|
#4 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
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 |
|
|
|
|
|
#5 |
|
Newbie
Join Date: May 2006
Posts: 21
Rep Power: 0
![]() |
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?
|
|
|
|
|
|
#6 |
|
Sexy Programmer
|
would help...
__________________
I would love to change the world, but they won't give me the source code! |
|
|
|
|
|
#7 | |
|
Professional Programmer
|
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:
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! ▄▄▄▄ |
|
|
|
|
|
|
#8 |
|
Newbie
Join Date: May 2006
Posts: 21
Rep Power: 0
![]() |
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.
|
|
|
|
|
|
#9 |
|
Sexy Programmer
|
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! |
|
|
|
|
|
#10 |
|
Newbie
Join Date: May 2006
Posts: 21
Rep Power: 0
![]() |
Yeah, I just realised that. I'm going to make a habit out of putting "return 0;" at the end of my programs.
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|