我如何观察(调试)布尔值 [英] How do I watch (debug) boolean values

查看:121
本文介绍了我如何观察(调试)布尔值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码,我不明白为什么P4(3,7)给出返回值true(1),因为这里7(ConTemp.XYCoord [1])大于5(ReCoordRo.XYCoord [1] ]),所以我想知道一种方法来监控布尔Rechteck1.contains(P4),看窗口不给我这个选项,所以我该如何去做呢? Thx



I have the following code and i don`t understand why P4(3,7)is giving returnvalue true (1) , since here 7(ConTemp.XYCoord[1]) is bigger than 5 (ReCoordRo.XYCoord[1]), so i would like to know a way to monitor the boolean Rechteck1.contains(P4), watch windows doesnt give me that option, so how do i go about it ? Thx

<pre>#include <iostream>
#include <array>

 using namespace std;
    class Punkt {
        public: int XYCoord [2]={};
        void setupCoord (int x, int y){
            XYCoord[0]=x;
            XYCoord[1]=y;
        }
    };
    class Rechteck {
        public: Punkt ReCoordLu,ReCoordRo;

        double flaeche(double x, double y){
            double xy=x*y;
            return xy;
            }
        bool contains ( Punkt &p){
            Punkt *ConTemp1=&p;
            Punkt ConTemp ;
            ConTemp = *ConTemp1;

            if (ConTemp.XYCoord[0]>=ReCoordLu.XYCoord[0]&&ConTemp.XYCoord[1]<=ReCoordRo.XYCoord[1]){
                return true;}
            else{
                return false;}
                };
        bool contains (Rechteck &){
            if (1){
                return true;}
            else
                return false;
            }
        };
int main()
{/* Rechteck sharedRectangle (Rechteck a , Rechteck b){
            Rechteck c;
            return Rechteck c;
            } */

        Punkt P1,P2,P3,P4;
        P1.setupCoord(1,1);
        P2.setupCoord(5,5);
        P3.setupCoord(3,3);
        P4.setupCoord(3,7);
        Rechteck Rechteck1;
        Rechteck1.ReCoordLu.setupCoord(3,3);
        Rechteck1.ReCoordRo.setupCoord(9,9);
Rechteck1.contains(P4) 

        cout<<"hello"<<P2.XYCoord[0]<<Rechteck1.ReCoordLu.XYCoord[0]
        <<Rechteck1.flaeche(5,5)<<Rechteck1.contains(P4) ;

        return 0;};





我尝试过:



监视窗口,调用堆栈窗口



What I have tried:

watch windows , call stacks windows

推荐答案

嗯。

看看你的包含方法:

Um.
Look at your contains method:
bool contains (Rechteck &){
    if (1){
        return true;}
    else
        return false;
    }

它总是返回 true 因为1是一个非零常数,任何非零值都是真 C / C ++

It always returns true because 1 is a non-zero constant and any nonzero value is "true" in C / C++


问题解决了!它实际上看起来像是我误解了Rechteck1.ReCoordLu.setupCoord(3,3)和

Rechteck1.ReCoordRo.setupCoord( 9,9)
Problem solved !It actually works looked like i just mistook Rechteck1.ReCoordLu.setupCoord(3,3)with
Rechteck1.ReCoordRo.setupCoord(9,9)


当你不理解你的代码在做什么或为什么它做它的作用时,答案是调试器

使用调试器查看代码正在执行的操作。只需设置断点并查看代码执行情况,调试器允许您逐行执行第1行并在执行时检查变量,这是一个令人难以置信的学习工具。



调试器 - 维基百科,免费的百科全书 [ ^ ]

掌握Visual Studio 2010中的调试 - 初学者指南 [ ^ ]

使用Visual Studio 2010进行基本调试 - YouTube [ ^ ]



调试器在这里向您展示您的代码在做什么你的任务是与它应该做的事情进行比较。

调试器中没有魔法,它没有发现错误,它只是帮助你。当代码没有达到预期的效果时,你就会接近一个错误。
When you don't understand what your code is doing or why it does what it does, the answer is debugger.
Use the debugger to see what your code is doing. Just set a breakpoint and see your code performing, the debugger allow you to execute lines 1 by 1 and to inspect variables as it execute, it is an incredible learning tool.

Debugger - Wikipedia, the free encyclopedia[^]
Mastering Debugging in Visual Studio 2010 - A Beginner's Guide[^]
Basic Debugging with Visual Studio 2010 - YouTube[^]

The debugger is here to show you what your code is doing and your task is to compare with what it should do.
There is no magic in the debugger, it don't find bugs, it just help you to. When the code don't do what is expected, you are close to a bug.


这篇关于我如何观察(调试)布尔值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆