Jump to content

Help With Learning C++


Scytheon3

Recommended Posts

I need some help with learning C++; basically the problem is that even the simplest programs (like hello world) fail to compile. The code I am using is:

#include <iostream>
using namespace std;
void main()
{
  cout << "Hello World!" << endl;   cout << "Welcome to C++ Programming" << endl; }

And the errors I get from this are:

C:\Users\******\Documents\Hello.c|1|iostream.h: No such file or directory|
C:\Users\******\Documents\Hello.c|2|error: syntax error before "namespace"|
C:\Users\******\Documents\Hello.c|2|warning: data definition has no type or storage class|
C:\Users\******\Documents\Hello.c||In function `main':|
C:\Users\******\Documents\Hello.c|5|error: `cout' undeclared (first use in this function)|
C:\Users\******\Documents\Hello.c|5|error: (Each undeclared identifier is reported only once|
C:\Users\******\Documents\Hello.c|5|error: for each function it appears in.)|
C:\Users\******\Documents\Hello.c|5|error: `endl' undeclared (first use in this function)|
C:\Users\******\Documents\Hello.c|4|warning: return type of 'main' is not `int'|
||=== Build finished: 6 errors, 2 warnings ===|

I got the code from http://www.hitmill.com/programming/cpp/helloWorld.htm but have tried many others and all come up with similar errors. The compiler I am using is Code::Blocks with the GNU GCC Compiler because all the other compilers literally take an hour to compile a hello world program which can't be right but I don't really have a clue what I'm doing wrong. Any help would be apreciated.

Link to comment
Share on other sites

Your main needs to return an int value. (so "int main()" and add a "return 0;" at the end).

Try a different compiler. You could install Visual C++ express if you really want to, but as a much more light weight option install cygwin with the G++ compiler. The current compiler not been able to find iosteam.h is the main problem.

Link to comment
Share on other sites

  • 2 weeks later...

Scytheon3, the problem is that the tutorial you are looking at is wrong. Main should not be declared as void, and doing so on modern compilers that adhere to C++ standards will cause the errors you encountered.

In C++, main should be declared as an int function, not a void function. For reasons why, please read the following articles on C++ standards:

http://faq.cprogramming.com/cgi-bin/smartf...p;id=1043284376

http://users.aber.ac.uk/auj/voidmain.shtml

For a better (correct) tutorial, check out: http://www.cplusplus.com/doc/tutorial/

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...