VSCode“无法打开'abs.c': [英] VSCode "Unable to open 'abs.c':

查看:32
本文介绍了VSCode“无法打开'abs.c':的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些简单的 C++ 代码(见下文),效果很好,可以在 Microsoft Visual Studio 中成功调试.

I have some simple code in C++ (see below), that works good and can be successfully debugged in Microsoft Visual Studio.

#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <map>
#include <set>
#include <algorithm>
#include <stdlib.h>
#include <iomanip>

using namespace std;

class Rational {
private:
    int numerator;
    int denominator;

public:
    Rational() {
        numerator = 0;
        denominator = 1;
    };
    Rational(int p, int q) {
        int divider = find_common_divider(abs(p), abs(q));
        p = p / divider;
        q = q / divider;
        if ((p < 0) && (q < 0)) {
            p = abs(p);
            q = abs(q);
        }
        else if ((p > 0) && (q < 0)) {
            p = -p;
            q = abs(q);
        }
        if (p == 0)
            q = 1;
        numerator = p;
        denominator = q;
    };

    int Numerator() const {
        return numerator;
    };
    int Denominator() const {
        return denominator;
    };
    int find_common_divider(int N1, int N2) {
        while ((N1 > 0) && (N2 > 0)) {
            if (N1 > N2)
                N1 %= N2;
            else
                N2 %= N1;
        }
        return N1 + N2;
    };

};

int main() {
    {
        const Rational r(3, 10);
        if (r.Numerator() != 3 || r.Denominator() != 10) {
            cout << "Rational(3, 10) != 3/10" << endl;
            return 1;
        }
    }

    {
        const Rational r(8, 12);
        if (r.Numerator() != 2 || r.Denominator() != 3) {
            cout << "Rational(8, 12) != 2/3" << endl;
            return 2;
        }
    }

    {
        const Rational r(-4, 6);
        if (r.Numerator() != -2 || r.Denominator() != 3) {
            cout << "Rational(-4, 6) != -2/3" << endl;
            return 3;
        }
    }

    {
        const Rational r(4, -6);
        if (r.Numerator() != -2 || r.Denominator() != 3) {
            cout << "Rational(4, -6) != -2/3" << endl;
            return 3;
        }
    }

    {
        const Rational r(0, 15);
        if (r.Numerator() != 0 || r.Denominator() != 1) {
            cout << "Rational(0, 15) != 0/1" << endl;
            return 4;
        }
    }

    {
        const Rational defaultConstructed;
        if (defaultConstructed.Numerator() != 0 || defaultConstructed.Denominator() != 1) {
            cout << "Rational() != 0/1" << endl;
            return 5;
        }
    }

    cout << "OK" << endl;
    return 0;
}

但是当我从行开始在 VSCode (UBUNTU 18.04) 中调试时const Rational r(3, 10) in main() with "Step into" up to line

But when I start debugging in VSCode (UBUNTU 18.04) from line const Rational r(3, 10) in main() with "Step into" up to line

int divider = find_common_divider(abs(p), abs(q));

调试器给出异常无法打开‘abs.c’:无法读取文件‘/build/glibc-OTsEL5/glibc-2.27/stdlib/abs.c’(错误:无法解析不存在的文件‘/build/glibc-OTsEL5/glibc-2.27/stdlib/abs.c')."

debugger gives exception "Unable to open 'abs.c': Unable to read file '/build/glibc-OTsEL5/glibc-2.27/stdlib/abs.c' (Error: Unable to resolve non-existing file '/build/glibc-OTsEL5/glibc-2.27/stdlib/abs.c')."

Microsoft Visual Studio 中不存在该异常,并且调试器转到函数find_common_divider".

That exception is absent in Microsoft Visual Studio and debugger goes to function "find_common_divider".

我的 VSCode 有什么问题?

What is wrong with my VSCode ?

推荐答案

你的 Visual Studio 代码没有问题,你只是没有 abs 的源代码,所以不能一步进去.忽略错误,点击step out 回到你的代码.

There is nothing wrong with your visual studio code, you simply don't have the source code for abs so can't step into it. Ignore the error, hit step out to get back to your code.

这篇关于VSCode“无法打开'abs.c':的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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