Welcome to HBH! If you have tried to register and didn't get a verification email, please using the following link to resend the verification email.

Just starting C++


ghost's Avatar
0 0

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 :


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
```markup
#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;
}

Some up to date sources: http://cprogramming.com http://cplusplus.com http://www.youtube.com/user/antiRTFM


interslice's Avatar
Member
0 0

Thanks. Just to tell you guys the book is called C++ Second Edition By Kris Jamsa Ph.D.


shadowls's Avatar
You Like this!
90 0

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.


ghost's Avatar
0 0

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:

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.


yours31f's Avatar
Retired
10 0

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


ghost's Avatar
0 0

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.