 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Ben L Guest
|
Posted: Wed Oct 22, 2003 6:38 pm Post subject: Strange output in debug mode of visual c++. |
|
|
Dear all,
The following code has different output if we use debugger of Visual Studio
to run it step by step(output of y changes from 3 to 4).
Could anyone help me explain it? Thanks.
Best regards,
Ben
----------------------------------------------------------------------------
---------
#include<iostream.h>
#include <stdlib.h>
int main()
{
int x = 0;
int y = 3;
int z = 3;
if(y-z && x*z || y > z)
cout << "True. " << (y-z && x*z || y > z) << endl;
else
cout << "False. " << (y-z && x*z || y > z) << endl;
cout <<"y is "<
cout <<"hello";
return 0;
}
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
Isaac Rodriguez Guest
|
Posted: Fri Oct 24, 2003 7:34 pm Post subject: Re: Strange output in debug mode of visual c++. |
|
|
Hi,
I got a question for you. What version of Visual Studio are you running? I
am running VC7 and both Release and Debug versions, running or debugging
show y=3.
I am assuming that you are running VC6 because you use #include<iostream.h>.
If you are using VC7 you should include <iostream> and use std::cout and
std::endl in your code. I don't think that has anything to do with what you
are seeing but you can give it a shot.
--
Regards,
Isaac Rodriguez
=======================
Software Engineer - Autodesk
"Ben L" <lbyj (AT) hotmail (DOT) com> wrote
| Quote: | Dear all,
The following code has different output if we use debugger of Visual
Studio
to run it step by step(output of y changes from 3 to 4).
Could anyone help me explain it? Thanks.
Best regards,
Ben
--------------------------------------------------------------------------
--
---------
#include<iostream.h
#include
int main()
{
int x = 0;
int y = 3;
int z = 3;
if(y-z && x*z || y > z)
cout << "True. " << (y-z && x*z || y > z) << endl;
else
cout << "False. " << (y-z && x*z || y > z) << endl;
cout <<"y is "<
cout <<"hello";
return 0;
}
|
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
Deming He Guest
|
Posted: Fri Oct 31, 2003 2:53 pm Post subject: Re: Strange output in debug mode of visual c++. |
|
|
Ben L <lbyj (AT) hotmail (DOT) com> wrote
| Quote: | Dear all,
The following code has different output if we use debugger of Visual
Studio
to run it step by step(output of y changes from 3 to 4).
Could anyone help me explain it? Thanks.
Best regards,
Ben
--------------------------------------------------------------------------
--
---------
#include<iostream.h
#include
int main()
{
int x = 0;
int y = 3;
int z = 3;
if(y-z && x*z || y > z)
cout << "True. " << (y-z && x*z || y > z) << endl;
else
cout << "False. " << (y-z && x*z || y > z) << endl;
cout <<"y is "<
cout <<"hello";
return 0;
}
I tried your code with MS VC++ 6.0 but failed to see what you described in |
your post. Even debugged through it.
I'd like to suggest you make some changes in your original code as:
#include
using namespace std;
int main(int argc, char* argv[])
{
int x = 0;
int y = 3;
int z = 3;
if(y-z && x*z || y > z)
cout << "True. " << (y-z && x*z || y > z) << endl;
else
cout << "False. " << (y-z && x*z || y > z) << endl;
cout <<"y is "<
cout <<"hello";
return 0;
}
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|