Trouble with Hello World variant

Don't Laugh... Just started. :(

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:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <iostream> // declares use of iostream library, which contains all our definitions

using namespace 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.
-_- Just didn't grab it in copy & paste.

Alright, well that's a relief, I was absolutely stuck wondering why it wasn't working. Maybe it's just Code::Blocks...

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

Is this true and how do I do that? Sorry for the complete newb moment, but I have no idea how to access my command line in Win 7.
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.

Thanks, Jose!
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.
Topic archived. No new replies allowed.