GIDForums  

Go Back   GIDForums > Computer Programming Forums > CPP / C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 05-Nov-2007, 20:07
Syrup1337 Syrup1337 is offline
New Member
 
Join Date: Nov 2007
Posts: 2
Syrup1337 is on a distinguished road

; 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:
//Example code
//Example.cpp

#include <iostream.h>

void main ()
{
	cout << "what am I doing wrong?";
}
return 0;

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  
Old 05-Nov-2007, 22:01
davekw7x davekw7x is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Left Coast, USA
Posts: 4,627
davekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to behold

Re: ; before return??


Quote:
Originally Posted by Syrup1337
K so, i'm really new to c++ ...visual c++ 5...what is it i'm missing?

The entire main() function goes in between the {} braces.

CPP / C++ / C Code:
{
    cout << "what am I doing wrong?";
    return 0;
}

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:
int main()
{
    cout << "what am I doing wrong?";
    return 0;
}

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:
#include <iostream>

using namespace std;

int main()
{
    cout << "What am I doing wrong?" << endl;
    return 0;
}

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  
Old 06-Nov-2007, 06:56
Syrup1337 Syrup1337 is offline
New Member
 
Join Date: Nov 2007
Posts: 2
Syrup1337 is on a distinguished road

Re: ; before return??


thanks alot
 
 

Recent GIDBlogLast Week of IA Training by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

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

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

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

All times are GMT -6. The time now is 03:47.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.