Welcome Guest [Log In] [Register]
We hope you enjoy your visit.


You're currently viewing the Ultimate 3D Community as a guest. This means that you can only read posts, but can not create posts or topics by yourself. To be able to post you need to register. Then you can participate in the community active and use many member-only features such as customizing your profile, sending personal messages, and voting in polls. Registration is simple, fast, and completely free.

Join our community!

If you are already a member please log in to your account to access all of our features:

Username:   Password:
Add Reply
Visual C++ 2008 Express Edition
Topic Started: Sep 25 2009, 05:52 AM (1,883 Views)
NGen
Member Avatar
Advanced Member
[ *  *  * ]
C'mon guys... really? Nothing here? No advice on what to use for different projects? What compilers have the best optimization? Well, hopefully this will get some things started...

http://www.microsoft.com/express/vc/

Along with looking pretty nice, Visual C++ has multiple useful features, its debugger pretty much tops almost all other Windows compilers available, and the best thing about it: It's free (The Express version, anyways. You need to register, but you just need a Windows Live account). However, the installation process can be a bit of a hassle.

--- Installation ---

When you get the installer, you don't get all of the files (which should be obvious from the ~4MB size). You get the file downloader, and then it installs the files. The downloading is where the problems can occur.

During the beginning of the download, you should see a "Calculating transfer rate..." message. When this changes to an actual Kb/S value, make sure that it's not 0Kb/s, as this obviously indicates a problem. I've found 2 causes of this:

- Windows Update
- Antivirus Firewalls

The answers to solving these problems should be self explanatory: Turn them off temporarily.


--- Creating a Project ---

Visual C++, like many other IDEs, works using projects. The main difference being that you can't simply compile a single C or C++ file without having a Project file associated with it (since the project file contains compilation settings).

When VC++ is open, press Ctrl + Shift + N ( Or go to File-> New-> Project ) to create a new project. A window should come up giving multiple templates, as well as asking you for a project name. For the sake of this tutorial, select Win32 Console Application.

The Win32 Application Wizard should then come up. Press Next.

You will then be given a few options. The first 4 determine how the project is compiled, and what entry points should be used (Console Application using main, Windows Application using WinMain, etc.). Then in the 3 below, you should see the Precompiled Header option checked. Precompiled headers are pretty much what is described: They are precompiled headers. These header files aren't read again when the project is compiled (unless a change was detected), they are linked. This can make compilation times faster, but in the end it doesn't really affect the speed of your program, and can make things more complicated when coding your program. I always un-check it.

You then also have the option of creating an empty project, where you don't get any files, and the compilation settings are just set. Don't check that for now, we'll use those files to show file management.

If you're seeing what I'm seeing, you'll probably see the Solution Explorer on the left. This will show you all of the files in your project. I'm seeing the stdafx.h files, and a few others in the folders available. I suggest you delete all of those, and just start with a fresh file. Hold ctrl and click to select multiple files, right click, and select remove. You'll have the option to just remove them from the project, or to just delete them altogether. Since we won't be using them, just delete them.

Then, right click the Source Files folder and select Add-> New Item. Make sure that C++ File is selected, and set a name for the file.

Go into your newly made file, and create a basic DOS application using the iostream library. Here's something just to save you some time:

Code:
 
#include <iostream>

using namespace std;

int main ( ) {
cout << "Hello world!";
cin.get ( );

return 0;
}



Copy and paste that into your file, and click on the Debug button on the top (It's a tilted green arrow). If the program runs, great! If not, follow the instructions for creating the project again. You probably missed a step, or did something other than what I said.



--- Creating a Release Executable ---

Creating an executable file to be ran as stand-alone is really quite simple, but it might be a bit hard to find at first. Next to the Debug button, click on the drop down menu (Should be Debug by default), and select release. Run your program, and either exit out of it or let it finish.

Open up Windows Explorer, and go to the My Documents folder, and go through the following path:

Visual Studio 2008-> Projects-> [Name of your project]-> Release

The Projects folder is the default place to put your projects. You can change this when you're creating a new project, or you can copy and paste all of the files into where you want them to be. Just keep the path structure to each file the same following the folder where your Solution file is (Looks like 2 gold Plus's with a 9 in the top right corner).

Your executable should be there, and should be able to run properly.


--- Disabling An Extremely Annoying 'Feature' ---

This is, non-arguably, THE most ridiculous thing I've ever heard, and this is another one of the few bad things about VC++. Fortunately, you only have to see this message once.

Go into the project where your working code is, and add some sort of screw-up in there, just to get the compiler to show an error. When this is done, you should be given the option to run the last successful build. This is only somewhat bad. The REALLY bad thing is that they added the 'Remember this selection' option. If you don't pay attention to the message, debugging will be hell. If you have a problem with your code, VC++ will still run a program. It won't stop the compilation and say 'Hey, something's wrong here!'. If you don't pay attention to the debug output window, you won't even know whether or not something is wrong with your code. You'll probably just think that your code isn't taking any effect, and that it's the library's fault, or it's the compiler's fault.

So, obviously, you should check the 'Remember this selection' option, and check NO. I don't know any way to change that after you've made your selection, so don't make that mistake.


--- The Build Output ---

If there's a syntax error, this is where it'll be shown. This guy is one of your best friends. You can find this lil' guy at the bottom of VC++, after you run a program. There should some text ( "Show output from: " ) with a drop-down menu next to it. Select Build, and you'll see all syntax errors there, as well as any linker errors, etc.


--- Using Intellisense ---

VC++ comes with a handy feature called Intellisense. You can see the results of the Intellisense database by including any of the standard libraries, and typing std::. A small menu should come up, listing every functions, class, typedef, EVERYTHING that belongs to that namespace. The same works with other structures (classes, structs, unions, etc.), and can be very useful as a reference.

When you type the opening parentheses of a function, the Intellisense also helps you out there as well, by showing the return type of the function, all of the function arguments, and the argument you are currently entering will be in bold. Hovering over a function will show this information as well, except without any arguments being in bold.

Variable information can be shown by hovering your mouse over the variable.


--- Accessing Included Files ---

As simple as this may be, some compilers actually don't support this, so I decided to include it.

Whenever you use the include pre-processor directive, you can right click the text giving the name of the file, and select "Open Document " to open the selected file.


--- Line Numbering ---

The most basic tool of all that almost every programmer needs is the line numbering. On the toolbar on top, select:

Tools-> Options...-> Text Editor-> C/C++-> Line numbers

Simply check that option, and you're good to go!


--- Adding Extra Build Directories ---

While simply copying and pasting your header and lib files into the VC directory in VC++'s Program Files folder is simple and easy, sometimes you just want to be able to tell VC++ to use a directory specified by you. Go to:

Tools-> Options...-> Projects and Solutions-> VC++ Directories

You'll often want to just set header and lib directories, so change the drop-down menu from Executable Files to either Library or Include files. Click on the New Directory button (A folder icon with a little star on the top-right, the buttons are just above the list of directories). A new entry should have been inserted, and a small button with the '...' dialogue. Click it to set your directory.



--- Changing your Build Type ---

Sometimes you might select Win32 Application when you really meant to select Window Application, or something else along those lines might have happened. In which case, you need to change the SubSystem setting. Go to:

Project-> Properties-> Configuration Properties-> Linker-> System

The SubSystem option should be there. Unfortunately, I don't know how to change a project to spit out DLL's when the option was already set, so you'll have to just copy and paste your code if no one else says how to do it.
Offline Profile Quote Post Goto Top
 
Dr. Best
Member Avatar
Administrator
[ *  *  *  *  *  * ]
Hi NGen and welcome to the community. That was a good first post for sure. Nice tutorial :thumb_up: .

Everybody needs some help to make the first steps with an unknown combination of IDE and compiler, especially if he's new to the language, so this should be useful for many members.

There are some things I'd like to add.

NGen
 
Creating an executable file to be ran as stand-alone is really quite simple, but it might be a bit hard to find at first. Next to the Debug button, click on the drop down menu (Should be Debug by default), and select release.
Your description suggests that you do not get a stand-alone executable, if you compile in Debug mode. That is not the case. You get an executable anyway. What is different in the debug version of an executable is the following:

  • Features to optimize the code for speed and small files are disabled.
  • The executable contains debug symbols, which allow the debugger to make the connection between source code and the data that is handled by the executable.
  • Some libraries (and your own code, if you use #ifdef _DEBUG) may use different code, which is slower, but helpful when searching for errors.
As a consequence debug executables have a lower performance and a bigger file size and reverse engineering is easier with them. On the other hand they can be built faster and the debugger can work with them. So unless you are doing benchmarks you should always work with debug executables during development. Whenever you release anything you should make sure that you are building in release mode.
BTW: You can add additional build modes using Build->Configuration manager (at least you can in the standard edition of VS). They are basically just a set of project settings.

NGen
 
So, obviously, you should check the 'Remember this selection' option, and check NO. I don't know any way to change that after you've made your selection, so don't make that mistake.
You can change the default option in Extras->Options->Projects and solutions->Build and execute.

NGen
 
--- Using Intellisense ---
[...]
IntelliSense also supports some very useful keyboard shortcuts. Pressing Alt+Right when the cursor is at the end of some incomplete identifier (like "std::co") either opens up a pop up from which you chose an auto-completion or completes the term automatically, if there is just one matching identifier (so you would get "std::cout" automatically). Pressing Ctrl+Shift+Space while you are in a parameter list shows you the declaration of the function again (just like when you first wrote the opening bracket).

NGen
 
Unfortunately, I don't know how to change a project to spit out DLL's when the option was already set, so you'll have to just copy and paste your code if no one else says how to do it.
That would be Project->Project settings->General->Configuration type.

P.S.: I am using the German version of Microsoft Visual Studio 2005 Standard Edition and translated the menu texts for this post. Some things may be slightly different in the English version of Visual Studio 2008 Express Edition.
Offline Profile Quote Post Goto Top
 
NGen
Member Avatar
Advanced Member
[ *  *  * ]
Quote:
 
Pressing Alt+Right when the cursor is at the end of some incomplete identifier (like "std::co") either opens up a pop up from which you chose an auto-completion or completes the term automatically, if there is just one matching identifier (so you would get "std::cout" automatically).


You can also just press Enter/Return.

I felt like this tutorial was necessary because I know that new users to C++ will often see so many options, and not know what to choose (I've seen Dev-C++ suggested multiple times around here... <_< ). They'll often just choose whatever everyone else is using. I made the tutorial for VC++ because it is a great IDE, but it can be confusing. Hopefully this will help.

Quote:
 
Hi NGen and welcome to the community. That was a good first post for sure. Nice tutorial :thumb_up: .


Thanks! B)


P.S.- I hope it doesn't seem like I joined just to post this, I definitely plan on being at least somewhat active. I visit the cplusplus forums, and also have 2 projects of my own to work on, so I won't be able to check every day.
Edited by NGen, Sep 25 2009, 09:18 PM.
Offline Profile Quote Post Goto Top
 
Reikyrr
Forum God
[ *  *  *  *  *  * ]
NGen
Sep 25 2009, 09:12 PM
I felt like this tutorial was necessary because I know that new users to C++ will often see so many options, and not know what to choose (I've seen Dev-C++ suggested multiple times around here... <_< ). They'll often just choose whatever everyone else is using. I made the tutorial for VC++ because it is a great IDE, but it can be confusing. Hopefully this will help.
I totally agree,
How many times have I almost killed my pc for not doing what I want when I want it, (it still doesnt though, After I installed express on win7 it just stated that it wasnt installed at all. Now I downloaded one from a torrent site. hope that it will work.)

P.s. I like codeblocks way better, but a lot of programs just wont compile (for example) I downloaded an example from the internets, it had a working binary and a project file with headers and that kind of stuff, I open, run compile and get a bunch of *** not defined.
My first (and only) hunch was that I was using the wrong compiler (Gnu CC), I have no problems with simple console programs like the one you made though.

Edit: Yay, I just got visual studio to work! Thanks for the example, as soon as i was able to use it, it was giving me a headache again.

You're like the paracetamol I never took.
Edited by Reikyrr, Sep 28 2009, 10:43 PM.
~Inspirational quote~
Offline Profile Quote Post Goto Top
 
NGen
Member Avatar
Advanced Member
[ *  *  * ]
Quote:
 
You're like the paracetamol I never took.

:P Thanks.

Quote:
 
Thanks for the example, as soon as i was able to use it, it was giving me a headache again.

What kind of problems was it giving you?
Offline Profile Quote Post Goto Top
 
Reikyrr
Forum God
[ *  *  *  *  *  * ]
Program database manager mismatch; please check your installation.

Codeblocks states that it can't link
libcpmt.lib
Edited by Reikyrr, Oct 2 2009, 07:47 PM.
~Inspirational quote~
Offline Profile Quote Post Goto Top
 
NGen
Member Avatar
Advanced Member
[ *  *  * ]
Er... why are you posting about getting a library to work in Code::Blocks in this thread?

Regardless, mind posting your specs?
Edited by NGen, Oct 2 2009, 09:01 PM.
Offline Profile Quote Post Goto Top
 
Adolph
Newbie
[ * ]
Hey everyone! I'm new to this forum! :clapping: Posted Image
Offline Profile Quote Post Goto Top
 
« Previous Topic · Tutorials · Next Topic »
Add Reply