Complete Beginner, Basic Questions.

Hi guys! I'm just starting out with "Teach Yourself C++ in 21 days." I'm on the first day... haha. Anyway, I've been doing XHTML for years so hopefully I'll catch on fast.

The lesson plan I'm following has me create a program called HelloWorld!. It tells you what to type and everything just so you see the basic steps of compiling, linking, ect. Anyway, I downloaded Code::Blocks and cannot figure out how to compile and link. I compile and it doesn't seem to do anything. I know I need to compile it and save it as an OBJ, then link it, and finally run it, but I can't seem to get it compiled. Just checked in case it was doing something after compiling, and I can't find how to link it either. After this, I tried finding JUST a compiler, downloaded Borland C++ but I don't even see a program to run. The book doesn't explain anything like this, nor does it recommend a specific compiler/IDE to use.

If anyone has experience with these programs, please help me out. Thanks a lot!
1. Are you running Windows?
2. Did you download the Code::Blocks with MingW installer? You Need MingW also on Windows.
3. On Windows, You May Want To Use Microsoft's Visual C++ IDE. The 2008 Express Edition is Free, if you can still find it.
I am running Windows. Vista 64.

I didn't download with the MingW Installer.

I was actually just downloading this to use and get through the first couple days of lessons. I'm currently downloading Ubuntu as well to install on my new machine. After that's done, I'll be using it exclusively.

Thanks for the reply. Should it be obvious how to compile and link once I get MingW installed? I've been working at a computer repair shop for 4 years and have just now gotten into programming... I'm still green -__-.
Last edited on
Onve you get MingW, Compiling and Linking will be an All-In-One Automated Process. Obviously, They will be done in different times. But yout PC will handle those processes by itself, you just need to click the Compile and Run button. CodeBlocks by itself, alone, does not compile, has no compiler. MingW is the GCC's Windows Port. It contains compilers and linkers. So, you should get CodeBlocks with the MingW installer.

EDIT: On Ubuntu, when you Install CodeBlocks, also GCC gets downloaded and installed. Or is it already present on a Ubuntu's Clean Install? Don't know, i just know you will just have to Install CodeBlocks, and GCC gets automatically configured.
Last edited on
Okay, I downloaded the Code::Blocks installer that included mingw, uninstalled the previous copy that was lacking mingw, and installed the new one. I followed the book exactly and typed the following into notepad, and saved it as a .cpp:

#include <iostream.h>

int main()
{
cout << "Hello World!\n";
return 0;
}


I wasn't instructed by the book to move lines 5 and 6 over slightly, but that is how it appears written in the book, although it's not reflected in this post because of what I assume is formatting issues. I load/open the file in Code::Blocks, it comes up in a tab and the text is in different colors, but I'm sure that is normal just like when viewing html source code or something similar. Anyway, I see three buttons above it called Build, Run, and Build and Run. Clicking these does nothing, and there is nothing in the "Build target:" field, and I'm unable to figure out how to set it to anything, if it even needs to be. I found the keyboard command for compile, which is ctrl+shift+f9 and I don't see anything visibly changing.

I know this is such a basic question, but everything I find on Google or here on the forum is over my head right now. If someone would take the time to explain it in "baby steps" I would greatly appreciate it. If I can get past this initial "hump" I think I'll pick up on it pretty quickly.
Last edited on
Hi there, I'm also a new starter. I'm using CodeBlocks and it is great. When you compile and run, look at the botton of CodeBlocks to see what the errors are. I'm pretty sure you're going to get some error about the namespace since you didn't declare what to use.

So try to open CodeBlocks and create a new project, name and locate it some where in HDD. then under source double click the main.cpp you'll be able to type in your code.

normally we'd use C++ standard namespace so make sure you add
using namespace std; below #include <iostream> or inside main()

and the shortcut for Build and Run is F9.
Two tips:

If you can, try Visual Studio Express, as mentioned above. Visual Studio is fantastic and so simple to use. If you do try it, the settings you want are:
New Project > select the option "win32 console application" > give it a name >
at the wizard click "next" > choose the option "empty project" > click "finish" >
then the project will be created.

Then add a new item (CTRL+ SHIFT +A) and add a cpp file named whatever you like. From that you can enter the hello world code and run it and stuff (Like with CTRL+ F5).

If you can't seem to add an item to the project bring up the solution explorer (CTRL+ ALT+ L) and make sure the project iteself is selected. Sometimes it isn't for me and that took forever to figure out the first time.


Anyways, Visual Studio is incredibly good and simple to use so I highly reccommend it.

The second tip:

In these forums, you can highlight a set of code with the cursor and then click the button <> under format. That makes the code part look like this in the post:

1
2
3
4
5
6
7
8
#include <iostream>
using namespace std;

int main()
{
    cout << "Hello World!";
    return 0;
}


Hope this helps!

EDIT: Here is a link to the free download/install at microsofts page for visual studio:

http://www.microsoft.com/visualstudio/en-us/products/2010-editions/visual-cpp-express

Also, if you have questions about programming, the msdn website (miscrsoft developer network) is a great place to search for excellent documentation.
Last edited on
Do NOT use "Teach Yourself C++ in 21 days.". It is outdated and is an all around poor excuse of a book.
Use one of the following books instead:
http://www.amazon.com/Primer-4th-Edition-Stanley-Lippman/dp/0201721481
http://www.amazon.com/Programming-Principles-Practice-Using-C/dp/0321543726
Also, a really great resource is this site iteself. There is a lot of great reference material here:

http://www.cplusplus.com/doc/tutorial/
Athar, why exactly is it outdated and such as you said?

I have no particular attachment to the book as it was just recommended to me. I'm only on day three so I haven't really learned a substantial amount. One thing I have noticed, even though it cites that you need no prior experience, that it doesn't explain a lot of the terms used. I was completely lost as early as day one as to what a compiler was. The author also introduces other terms without explaining them, such as "preprocessor" (I now loosely understand the term).

Are the books you recommend extremely beginner-friendly? Are they able to teach within a few months at most? I'm not on a time-limit but I would like to know the basics of c++ before summer is over and I start undergrad, much like html and having basic pages designed in the first few weeks.

Thanks, any other recommendations whom anyone has would be greatly appreciated.
Last edited on
Topic archived. No new replies allowed.