Trying to make myself a Hello World-type file that I can display the basics of C++, along with some comments for my own learning purposes. Here's what I have:
#include <iostream> // declares use of iostream library, which contains all our definitions
usingnamespace std; // references a particular namespace 'std' within iostream
int main() // declares the main function, which is opened and closed by brackets
{
// cout is a basic output expression which relates to the console, or screen.
// it assigns things to be displayed on screen
// Text is included in the case, and must be enclosed by quotation marks. endl; provides a line break
cout << "Hello world!" << endl;
int x;
x = 7;
int y;
y = 4;
int answer;
answer = x + y;
cout << "The magic number is: " << answer << endl;
return 0;
Trouble is, when I compile in Code::Blocks, only 'Hello World!' shows up.
Can anyone point out and explain where my syntax errors are?
It beats me. Your code compiles fine with g++: http://www.ideone.com/w8LWg , that is, assuming that the ending bracket missing in this post is not missing in your code.
Not true. G++, AFAIK, is downloadable. Think about it: Microsoft does a C++ compiler and it is not G++. If any compiler were to be included, it would be Microsoft's, not an open source competition. If you want Microsoft's compiler, download Visual Studio Express for free. Visual Studio is the best IDE out there anyway, hands down.
Can I ask a second question? In the tutorials it keeps talking about how there is a compiler built into windows, something to the effect of:
-o g++ uncompiled_code_name.cpp
Are these your Code::Blocks tutorials? Because Code::Blocks usually installs MinGW (http://www.mingw.org/) alongside itself, in which case you have got g++ (the GNU C++ compiler) on your system and probably can access it from the command line.
Awesome, thanks for straightening me out. The code looks fine now, I managed to get C::B to display it right too. Onto variables & data types tomorrow.
I'll look into getting VSE tomorrow; if you say it's better I'll trust your judgment. For tonight, though, I'm gonna crash.
Visual Studio is good, but I wouldn't say it's the best. I used it for a while and didn't like it very much, also vc++ is still behind g++ when it comes to the implementation of C++11. I personally use Eclipse right now - since you're not paying money for it either way, you may want to look into various IDE's and just see which one you like best. Not all on one day of course, but over a longer period of time.