RE: Just starting C++

interslice wrote:
Hey guys.. i thought i would get into learning C++ and I've borrowed a book on the topic. There is a code in the book, that is supposed to work but its not working for me :

Code

#include <iostream.h>

void main(void)
{
cout << "Hello Everyone";
}

This is exactly as it is in the book. Am i doing something wrong? Or is the book out of date?

That looks like a horrible mixture between C and C++. You say you are coding in C++? Then here are some pointers
-C headers are in the format of <example.h> or <cexample>
-C++ headers are in the format of <example>
-in C, the main function can return any type you please
-In C++, the main function has to be of type int (integer).

The code should look like

Code

#include <iostream>
using namespace std;
//Note that inside the main() parentheses, you may see a variety of //different parameters.
int main(){
cout<<"Hello Everyone!";
return 0;
}

RE: Just starting C++

I have also just started c++ and i am using the book called "C++ Programming" by D.S Malik

i have leard a lot from the book so far. for example i have leard how to use if and else statements. i have just started the book and it is working for me. The book has a lot of example and challenges for you to try as you make progress. I highly recommend this book.

If you think my post are useful to you, please vote for them. Thank You

knowledge is powerful itself - SHADOWLS

Made by:agentmax69, but remastered by: KvK

Coffee

Author

RE: Just starting C++

Member

Posts:Location:Joined: 01.01.70 Rank: Guest

Posted on 09-10-08 03:55

Yeah, pwnzall pretty much summed it up. Don't forget to indent within functions and control statements either, as it will be much easier to read and follow. Also, comments can be a lifesaver, both for yourself and others. You also don't need to specify a namespace, you can just write:

Code

std::cout << "Hello Everyone";

You're probably better off just visiting one of the sites pwnzall posted. That book seems to be using older standards. The cplusplus site has a lot of nice resources and tutorials, so you might want to check it out.

Author

RE: Just starting C++

and if you would like, I have a c++ site that is just getting started. Pwnzall has the first tutorial on the site, and there is a forum that I frequent, So if you have any questions feel free to register and post there.

CTheCode.com

Debugging is what programmers do to beta software to make it take up more room on your hard drive if it is running too efficiently.

Author

RE: Just starting C++

Member

Posts:Location:Joined: 01.01.70 Rank: Guest

Posted on 09-10-08 04:15

yours31f wrote:
and if you would like, I have a c++ site that is just getting started.

... Or you could use established resources while that site gets past "getting started". Yay for blatant advertising.

Edit: Glad that post disappeared... I was about to rip into it for very obvious reasons.