PDA

View Full Version : [Tutorial] Writing your first Visual C++ Application


xilica
05-22-2002, 05:20 PM
Yo, how's it going?

Adding the Interface:

In this tutorial I will guide you through writing your first Visual C++ Application!!

To get started load Microsoft Visual C++. When it loads up, click:
File-->New

A dialog box is displayed. Here, Select Win32 Console Application. Under the Project Name (which is on the right side of this dialog box) type: Hello World. Now, click OK. Another dialog box loads. Simply click Finish. After you click Finish another box pops up. Simply click OK.

After all that is done. Click the menu bar named:
Project-->Add to Project-->New.... Select C++ Source File and on the right side of the box under Name type Hello World.


Adding the Code:

In the white area of the document enter this code:


#include <iostream>
#include <string>

using namespace std;
int main () {
string name;
cout << "Hello World. What is your name?";
cin >> name;
cout << "Hello,"
<< name << ". Have a good day."
<< endl;
return 0;
}


Once you are finished typing the code into the edit window we are going to execute your program. Locate the button which looks like a huge ! (exclamation mark). A box will appear. Press OK to this. Your code should execute as many times as you want. All you have to do is press that huge ! (exclamation mark).


Analyzing the Code:

The first two lines of <iostream> and <string> mean that you will include these in your program. the IO in the iostream means input and output. A string, which you are including, is a series of 0 or more characters. These characters can be number of lettets. When you type the code that the user sees, notice that you put "cout" for it. The words "cout" and "cin" mean that it is being outputted and inputted. Notice how you put "<<" when you are coding something the user sees and ">>" when you are coding something the machine will interpret. After the user types his/her name it will then take that name and display with the sentence in which you want it to.

Congratulation on completing and coding your first Visual C++ tutorial.


note: Please feel free to add anything to this posts whether it may be positives or negatives.

Afr0m@n
12-09-2003, 10:51 AM
Hi!

I just wanted to let you know that you cannot use "string". In ansi C++ you'll have to use char arrays. And in Visual C++ you'll have to use CString.



char[10] //this would create a string that could be assigned 10
characters



Then there's another thing I'd like to point out : The using namespace std; thing doesn't work. I've tried it several times in my compiler, and the only times that it works is when I leave out the std thingy. It says that stdd is not a namespace. (I'm using Visual Studio 6.0).

little birdy
12-09-2003, 01:50 PM
o_O

std is a namespace, and home to many important things.

gold_dragon
12-09-2003, 03:22 PM
Originally posted by Afr0m@n
Hi!

I just wanted to let you know that you cannot use "string". In ansi C++ you'll have to use char arrays. And in Visual C++ you'll have to use CString.

Since you are using Visual Studio 6.0, then yes, you will have to use <string.h>. The code is correct with the new standard. <string> is correct and if you look at the header, you will see that it uses the std namespace.



Then there's another thing I'd like to point out : The using namespace std; thing doesn't work. I've tried it several times in my compiler, and the only times that it works is when I leave out the std thingy. It says that stdd is not a namespace. (I'm using Visual Studio 6.0).

In Visual Studio 6.0, it ignores the using namespace std; but you can still have it. If you go with the newer standard then not having it spits out a lot of errors.

the_actriser
12-19-2003, 05:09 PM
Forgive my ignorace, but I am new to this, what is it that namespace is defining?

gold_dragon
12-20-2003, 08:12 AM
Originally posted by the_actriser
Forgive my ignorace, but I am new to this, what is it that namespace is defining? STL Library. STL library uses the std namespace.

FatBob
01-02-2004, 04:14 AM
Where do i get Microsoft Visual C++?