【问题标题】:debugging c++ with xcode [duplicate]用xcode调试c ++ [重复]
【发布时间】:2018-01-14 21:17:45
【问题描述】:

我是编程新手,最近正在学习 C++。我有一台 Apple 笔记本电脑,它带有 Xcode。我最近开始使用调试器,但我不太了解它。是否有不同的视图可以调试,或者 c++ 在调试时是否总是这样? 调试器中代码的屏幕截图

这只是一个低级语言的列表。

根据调试器,我在第 98 行有问题,但我的代码甚至没有那么长。

#include <iostream>
#include <fstream>
using namespace std;


ifstream infile;
int main()
{
    infile.open("number.txt");

    int x = 1, value;
    float avg, sum = 0; //numb;
    int Max, Min;

    cout <<"Enter Numbers to Calculate, type 0 when finished."<<endl<<endl;

    int numb[x-1];
    value = numb[0];

    infile >> value;


    Min = value;
    Max = value;

    while(value != 0)
    {
        infile.open("number.txt");
        sum = sum + value;
        avg = sum / x;
        x++;
        numb[x-1] = value;

        if(Max < numb[x-1] )
        {
            Max = numb[x-1];

        }
        if(Min > numb[x-1])
        {
            Min = numb[x-1];
        }
        infile >> value;

        infile.close();

    }

    cout <<"You Entered " << x-1 <<" Numbers."<<endl;
    cout <<"The Max is: "<<Max<< " The Min is: "<<Min<<endl;
    cout <<"The Sum of the Numbers is: "<<sum<<endl;
    cout <<"The Average of the Numbers is: "<<avg<<endl;

    infile.close();
    return 0;
}

这就是我正在调试的,很简单的代码,我只是想感受一下Xcode调试器的感觉。任何使用 Xcode 的建议都会很棒。 谢谢。

【问题讨论】:

  • 你应该修正你的缩进。缩进不佳会导致大量代码失败/错误,并使其他人难以阅读。
  • 您能否详细说明缩进,我对编码还很陌生,我想知道如何使我的代码更易于阅读。您使用了哪些技巧来使代码在视觉上更好?
  • 这是比较好的款式之一wiki
  • int numb[x-1]; 不是很有意义,因为 x 是您稍后才确定的值。 (当您声明 numb 时,x 为 1。想想这意味着什么。)不过,对于您正在计算的任何值,您都不需要数组。
  • 不,它不应该是那样的。它应该看起来像源代码。某处有设置或菜单项。

标签: c++ xcode debugging


【解决方案1】:

您看到的是代码的反汇编。作为参考,程序集是“由汇编程序转换的低级符号代码”,是一种令人讨厌的编程语言。查看程序集是一种高级的调试方法,现在已经没有多少人使用了。已经有关于这个的问题请看XCode Debugger: Why is it only showing me assembler?

【讨论】:

  • 太棒了!非常感谢 Alex G 1. 我了解到特定视图称为代码的汇编 2. 我修复了问题 3. 我将根据您的 wiki 参考研究更好地格式化我的代码。
  • @JerryBerry 我在问题中格式化了您的代码,例如。如果它对您有用,请随时将其标记为答案。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-04-14
  • 2011-11-12
  • 2017-03-16
  • 2023-02-06
  • 1970-01-01
  • 2012-05-16
  • 1970-01-01
相关资源
最近更新 更多