954,483 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Is this a runtime error?

I wrote a simple program to print out Testscore in Visual Studio .Net 2003
and got the following messages when trying to run it.

'TestScore.exe': Loaded 'D:\Documents and Settings\pooleb\My Documents\Visual Studio Projects\TestScore\Debug\TestScore.exe', Symbols loaded.
'TestScore.exe': Loaded 'D:\WINDOWS\system32\ntdll.dll', No symbols loaded.
'TestScore.exe': Loaded 'D:\WINDOWS\system32\kernel32.dll', No symbols loaded.
The program '[3920] TestScore.exe: Native' has exited with code 0 (0x0).

This is the program:

#include <iostream>
using namespace std;
int main(void)
{
	short testScore;
		testScore = 3;
		cout << "Your test score is " << testScore << "\n";
		return 0;
}


<< moderator edit: added [code][/code] tags >>

It is from an example in C++ Demystified by Jeff Kent.

Am I doing something wrong?

Thanks, BandM

bandm
Newbie Poster
19 posts since Jun 2005
Reputation Points: 10
Solved Threads: 0
 

>Am I doing something wrong?
Nope. Your program opens a command shell, executes sucessfully, and having nothing further to do the command shell is closed. Happens in the blink of an eye.

http://faq.cprogramming.com/cgi-bin/smartfaq.cgi?answer=1043803465&id=1043284385

Dave Sinkula
long time no c
Team Colleague
5,058 posts since Apr 2004
Reputation Points: 2,780
Solved Threads: 314
 

If you want to see the result, you could do the following :

add

#include <stdlib.h>


before the first line of your program

add

system("pause");


before the end of your main() function.

CrazyDieter
Junior Poster
108 posts since Jul 2005
Reputation Points: 11
Solved Threads: 6
 
prog-bman
Junior Poster
109 posts since Nov 2004
Reputation Points: 14
Solved Threads: 4
 

include the header file --> #include

then add this --> system("pause");
before the return 0;


*It causes the program to stop until it detects any keypress...

chiwawa10
Junior Poster
156 posts since Jul 2005
Reputation Points: 88
Solved Threads: 27
 

Yes, but as prog-bman said, (all my apologies :o ), this is not very smart, as using system("something") calls the external program something.exe.

using getchar(); is in fact much more portable between different systems

CrazyDieter
Junior Poster
108 posts since Jul 2005
Reputation Points: 11
Solved Threads: 6
 

Is this something to do with studio .Net? because in VS 6.0 it doesn't do this.

bandm
Newbie Poster
19 posts since Jun 2005
Reputation Points: 10
Solved Threads: 0
 

I think VS 6.0 automatically places a pause after your program has executed.

prog-bman
Junior Poster
109 posts since Nov 2004
Reputation Points: 14
Solved Threads: 4
 

Thanx All!

Your suggestions worked :p

I do want to know why, when I cut and paste one of the Cplusplus snippets
here and paste it into my editor and try to build it I get an error.
I am just starting out so, please be patient.

Thanx, BandM

bandm
Newbie Poster
19 posts since Jun 2005
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You