Scytheon3 Posted June 6, 2010 Share Posted June 6, 2010 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. Quote Link to comment Share on other sites More sharing options...
Sparda Posted June 6, 2010 Share Posted June 6, 2010 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. Quote Link to comment Share on other sites More sharing options...
fsck Posted June 14, 2010 Share Posted June 14, 2010 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/ Quote Link to comment Share on other sites More sharing options...
Mr-Protocol Posted June 15, 2010 Share Posted June 15, 2010 Book I learned by was "How to program C/C++ 6th edition" I think they are on 7th now? I also have a book comparable to War and Peace that is called "Mastering C/C++" Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.