I have a base of knowledge in Java and VB ,net but coming up in my school career is a class called “Problem Solving in C++” So where do you start learning a new language? The Hello World! program
This summer while I waste some time at work my plan is to get prepared for this course by grabbing a book and learning about the C++ language.
I chose a book called “C++ From the Ground Up” by Herbert Schildt. So far it is well written and seems like an excellent choice.
This is probably the same example you are going to find if you do a search for a C++ Hello World! It’s nothing special but it always fun when you start learning something new.
So here it is, enjoy!
/* Hello World in C++*/
#include <iostream>
using namespace std;
//this is so you don’t have to qualify
//each thing like std::cout, you can just use cout
int main()// main() is where program execution begins
{
cout << “\nHello World!!\n\n”; //write the string to the buffer
cout << endl; //clears the buffer
return 0; //return success 0
}
That’s it! Exciting stuff I know. I saved it as HelloWorld.cpp. As far as compiling it I am using Ubuntu Linux at home so I used the g++ compiler you can install the compiler using this command in the terminal:
sudo apt-get install g++
Then to compile you can use this command (make sure you are in the directory where your code file is located:
g++ filename -o what_you_want_executable_to_be_called
so in my case
g++ HelloWorld.cpp -o -hello
Then to run this bad boy you just type:
./name_of_executable
in my case
./hello
Obviously this is just a incredibly small peek into the very basics of C++. There are different compilers for different systems and even different versions of C++. Hopefully this was helpful to another noob like myself. Leave a comment if it was.
Further Reading:
- WikiBook on C++
- C++ From the Ground Up (Amazon Link)