Computing.Net > Forums > Programming > C++ and Ms Visual C++

C++ and Ms Visual C++

Reply to Message Icon

Original Message
Name: chris (hotshot)
Date: October 5, 2002 at 11:53:37 Pacific
Subject: C++ and Ms Visual C++
OS: 98
CPU/Ram: p4/256x2
Comment:

Well I got a problem... I recently started learning C++. Anyway I us Visual C++. Can anyone give me step-by-step instruction on what to do to make a program run?? Here is what I do:

Open Visual C++
>Click on the page (aka new text file)
>write in some code, here is a simple example:

#include
#include

int main(int nArg, char* pszArgs[])

{
cout Then I go file > Save As> call it something and add .cpp to the end
>Build > Build (then fix the error's if any)
>build > execute

Now that usually works and what ever the program is it will work normally in Visual... But once I got to where I saved the file and open the file (the compiled code) it automatically closes at the last step. for example the simple hello code would closes right away and I wouldn’t see nothing. Or a code that ask for 2 number and add em both together would close right after both the 2 number would be entered....

What am I doing wrong??? I'm pretty sure the code is right cause it runs perfectly in MS Visual.


Report Offensive Message For Removal


Response Number 1
Name: Ronin
Date: October 5, 2002 at 12:46:08 Pacific
Reply: (edit)

There is really no incentive for windooze to keep the app open if it's done all of it's processing. I'm kind of surprised a windows app would close out on its own, but that's typical of a dos console app.

Try adding

getch(); or
while(!kbhit());

After your last cout statments, but before your code terminates. I *think* they
re defined in conio.h in ms visual c++.


Report Offensive Follow Up For Removal

Response Number 2
Name: Richard
Date: October 7, 2002 at 09:40:04 Pacific
Reply: (edit)

Also try

#include "stdlib.h"

(replace " with greater then and " with less then)

system("PAUSE");


Report Offensive Follow Up For Removal







Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: C++ and Ms Visual C++

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software




Have you ever used OpenOffice?

Yes, as my main suite.
Yes, occationally.
Yes, but only once.
No, never.


View Results

Poll Finishes In 5 Days.
Discuss in The Lounge