Is this a runtime error?

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Jun 2005
Posts: 19
Reputation: bandm is an unknown quantity at this point 
Solved Threads: 0
bandm's Avatar
bandm bandm is offline Offline
Newbie Poster

Is this a runtime error?

 
0
  #1
Jul 6th, 2005
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:

  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
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 4,443
Reputation: Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future 
Solved Threads: 250
Team Colleague
Dave Sinkula's Avatar
Dave Sinkula Dave Sinkula is offline Offline
long time no c

Re: Is this a runtime error?

 
0
  #2
Jul 6th, 2005
>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
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 76
Reputation: CrazyDieter is an unknown quantity at this point 
Solved Threads: 3
CrazyDieter's Avatar
CrazyDieter CrazyDieter is offline Offline
Junior Poster in Training

Re: Is this a runtime error?

 
0
  #3
Jul 7th, 2005
If you want to see the result, you could do the following :

add
  1. #include <stdlib.h>
before the first line of your program

add
  1. system("pause");
before the end of your main() function.
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 108
Reputation: prog-bman is an unknown quantity at this point 
Solved Threads: 3
prog-bman prog-bman is offline Offline
Junior Poster

Re: Is this a runtime error?

 
0
  #4
Jul 7th, 2005
Or you could be smart and not use a system command.
http://faq.cprogramming.com/cgi-bin/...&id=1043284385
Join me on IRC:
Server: irc.daniweb.com
Channel: #C++

Chat Via:
http://daniweb.com/chat/minichat.php
or
Your favorite IRC client.
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 34
Reputation: chiwawa10 is an unknown quantity at this point 
Solved Threads: 5
chiwawa10's Avatar
chiwawa10 chiwawa10 is offline Offline
Light Poster

Re: Is this a runtime error?

 
0
  #5
Jul 7th, 2005
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...
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 76
Reputation: CrazyDieter is an unknown quantity at this point 
Solved Threads: 3
CrazyDieter's Avatar
CrazyDieter CrazyDieter is offline Offline
Junior Poster in Training

Re: Is this a runtime error?

 
0
  #6
Jul 7th, 2005
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
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 19
Reputation: bandm is an unknown quantity at this point 
Solved Threads: 0
bandm's Avatar
bandm bandm is offline Offline
Newbie Poster

Re: Is this a runtime error?

 
0
  #7
Jul 7th, 2005
Is this something to do with studio .Net? because in VS 6.0 it doesn't do this.
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 108
Reputation: prog-bman is an unknown quantity at this point 
Solved Threads: 3
prog-bman prog-bman is offline Offline
Junior Poster

Re: Is this a runtime error?

 
0
  #8
Jul 7th, 2005
I think VS 6.0 automatically places a pause after your program has executed.
Join me on IRC:
Server: irc.daniweb.com
Channel: #C++

Chat Via:
http://daniweb.com/chat/minichat.php
or
Your favorite IRC client.
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 19
Reputation: bandm is an unknown quantity at this point 
Solved Threads: 0
bandm's Avatar
bandm bandm is offline Offline
Newbie Poster

Re: Is this a runtime error?

 
0
  #9
Jul 7th, 2005
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
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC