944,044 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 2921
  • C++ RSS
Jul 6th, 2005
0

Is this a runtime error?

Expand Post »
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:

C++ Syntax (Toggle Plain Text)
  1. #include <iostream>
  2. using namespace std;
  3. int main(void)
  4. {
  5. short testScore;
  6. testScore = 3;
  7. cout << "Your test score is " << testScore << "\n";
  8. return 0;
  9. }
<< moderator edit: added [code][/code] tags >>

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

Am I doing something wrong?

Thanks, BandM
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
bandm is offline Offline
19 posts
since Jun 2005
Jul 6th, 2005
0

Re: Is this a runtime error?

>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/...&id=1043284385
Team Colleague
Reputation Points: 2780
Solved Threads: 312
long time no c
Dave Sinkula is offline Offline
4,790 posts
since Apr 2004
Jul 7th, 2005
0

Re: Is this a runtime error?

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

add
C++ Syntax (Toggle Plain Text)
  1. #include <stdlib.h>
before the first line of your program

add
C++ Syntax (Toggle Plain Text)
  1. system("pause");
before the end of your main() function.
Reputation Points: 11
Solved Threads: 6
Junior Poster
CrazyDieter is offline Offline
106 posts
since Jul 2005
Jul 7th, 2005
0

Re: Is this a runtime error?

Or you could be smart and not use a system command.
http://faq.cprogramming.com/cgi-bin/...&id=1043284385
Reputation Points: 14
Solved Threads: 4
Junior Poster
prog-bman is offline Offline
108 posts
since Nov 2004
Jul 7th, 2005
0

Re: Is this a runtime error?

include the header file --> #include <stdlib.h>

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


*It causes the program to stop until it detects any keypress...
Reputation Points: 88
Solved Threads: 27
Junior Poster
chiwawa10 is offline Offline
156 posts
since Jul 2005
Jul 7th, 2005
0

Re: Is this a runtime error?

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
Reputation Points: 11
Solved Threads: 6
Junior Poster
CrazyDieter is offline Offline
106 posts
since Jul 2005
Jul 7th, 2005
0

Re: Is this a runtime error?

Is this something to do with studio .Net? because in VS 6.0 it doesn't do this.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
bandm is offline Offline
19 posts
since Jun 2005
Jul 7th, 2005
0

Re: Is this a runtime error?

I think VS 6.0 automatically places a pause after your program has executed.
Reputation Points: 14
Solved Threads: 4
Junior Poster
prog-bman is offline Offline
108 posts
since Nov 2004
Jul 7th, 2005
0

Re: Is this a runtime error?

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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
bandm is offline Offline
19 posts
since Jun 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: copy constructor problem
Next Thread in C++ Forum Timeline: Serial Port





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC