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 :
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
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.
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.