Fog Creek Software
Discussion Board




C++ Problem

Hi,
Am very new to C++. I have just written my first "Hello World" program. I have compiled it using Microsoft Visual Studio.Net and formed a .EXE file. Am trying to run the .EXE program but am getting nothing.

Probably it's because am using Windows XP. Are there any further setting i should configure for it to work?

Please help me or refer me to a forum i can send the question.

Thanks

peter
Friday, August 15, 2003

I would suggest posting to the microsoft.public.vc.language newsgroup.

sgf
Friday, August 15, 2003

Hi Peter,

You don't say whether you are creating a console app, a regular win32 app, an MFC app, or a managed C++ app, so i'll assume you are creating a console app that displays "Hello World!" to stdout.

It probably looks something like this:

// Hello.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream.h>

int _tmain(int argc, _TCHAR* argv[])
{
    cout << "Hello World!";

    return 0;
}

The only thing this program does is display "Hello World!", it doesn't stop execution so that you can view the output.  Thus the output window flashes up on screen and disappears befure you have a chance to view it.

There are several ways to correct this.

For example you can include the console input/output header and then make a call to getch();.

// Hello.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream.h>
#include <conio.h>

int _tmain(int argc, _TCHAR* argv[])
{
    cout << "Hello World!" << endl;

    getch();

    return 0;
}

This allows you to view the output.

Dave B.
Friday, August 15, 2003

Hi

If you are new to C++, I suggest that you work through a tutorial that focuses on just the C++ language. There are tons of settings in Visual Studio that a beginner can find very confusing, and the MS classes are not a standard part of the C++ language.

Get the basics down first using a simple compiler like GCC or DevC++ (both free), and then learn how to use the Visual Studio IDE.

Bood luck

Chris Rose
Sunday, August 17, 2003

*  Recent Topics

*  Fog Creek Home