![]() |
|
#1
|
|||
|
|||
; before return?K so, i'm really new to c++ and feel really stupid looking at how i'm still learning forloops and ifelse statements and other people have these massive codes, but anyways... I'm working on an assignment, and just got this compiler visual c++ 5 and i've installed it, but with one issue.
I tried just making an example program to make sure I could do this right and I keep having the same problem... what is it i'm missing? CPP / C++ / C Code:
C:\Program Files\DevStudio\MyProjects\example\example.cpp(10) : error C2143: syntax error : missing ';' before 'return' Error executing cl.exe. Last edited by LuciWiz : 06-Nov-2007 at 13:03.
Reason: Please insert your C/C++ code between [cpp] & [/cpp] tags
|
|
#2
|
|||
|
|||
Re: ; before return??Quote:
The entire main() function goes in between the {} braces. CPP / C++ / C Code:
Now you have another problem: You declared main() to have a "void" return type, but have a statement that returns an integer value. In fact, the C++ standard requires that main() have an int return type although some compilers, do not enforce that. See footnote. So the main function should properly be something like the following: CPP / C++ / C Code:
Regards, Dave Footnote: Visual C++ version 5? That's incredibly old and limited to pre-standard C++ (no support of the C++ standard library, I believe). Can't you get a more recent compiler? Free downloads of Visual Studio version 2008 Express are available from Microsoft, and there are freebies from other vendors as well. I just hate to see new students learning bad habits because of limitations of ancient and obsolete tools. The real program should look more like the following, as you will see in any decent (and recent) book or tutorial. I don't know whether it will even compile with version 5 of Visual C++: CPP / C++ / C Code:
Note use of <iostream> instead of the officially deprecated <iostream.h>. The using namespace std; statement or some other idiom taking namespaces into account is required with the h-less header. You should be getting used to standard ways of doing things. In other words: Trying to learn C++ with a compiler like Visual C++ version 5, that doesn't support the C++ standard library, is an exercise in futility. You may be able to run some programs and you may be able to dumb down examples using standard language features and standard libraries so that you can compile them, but what's the point? |
|
#3
|
|||
|
|||
Re: ; before return??thanks alot
|
Recent GIDBlog
Last Week of IA Training by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Re: Things to Avoid in C/C++ -- gets() , Part 1 | WaltP | C Programming Language | 5 | 21-Jun-2007 12:13 |
| need help with a console menu system | BullBuchanan | CPP / C++ Forum | 6 | 20-Aug-2006 14:46 |
| Reading non ASCII with read() | Atomical | C Programming Language | 8 | 13-Sep-2005 14:30 |
| Problem with one variable | bretter | CPP / C++ Forum | 1 | 16-May-2005 07:20 |
| C++ file I/O | CronoX | CPP / C++ Forum | 36 | 09-Mar-2004 17:28 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The