1

こんにちは、私の基本的な英語で申し訳ありません。mpf_class から String に変換しようとしています。関数 (get_str()) があることは知っていますが、数字とその指数のみが表示されます。式全体を文字列で取得したい。ostreamstring を使用してみましたが、動作しますが、それを行う別の方法があるかどうかを知りたいです。私が自分自身を明確にしたかどうか教えてください。

基本的に私がしたことは:

std::ostringstream show;
mpf_class result, Afact,Bfact,Cfact;
result=Afact*Bfact/Cfact;
show << result;
ui->lineEdit_5->setText(QString::fromStdString(show.str()));

ご覧のとおり、私は QT プロジェクトで作業しており、QLineEdit で結果を表示する必要があり、ostreamstring で動作します。それを行うgmp関数があるかどうか疑問に思っていました。ありがとう

4

1 に答える 1

0

これが役立つかどうかはわかりませんが、実際にオブジェクトを印刷しmpf_classて、典型的なオブジェクトとして I/O マニピュレータを使用できfloatます。

これが私のコードです

#include <gmpxx.h>
#include <iostream>
#include <iomanip>

int main(void) {
    mpf_class a;
    a = 3141592653589793.2;

    std::cout << a << std::endl;
    // Outputs 3.14159e+15

    std::cout << std::uppercase << std::showpos << std::setprecision(3) << a << std::endl;
    // Outputs +3.14E+15

}

std::ostringstream次に、の代わりにオブジェクトを使用できますstd::cout

参考:https ://gmplib.org/manual/C_002b_002b-Formatted-Output.html

于 2019-02-28T21:41:19.637 に答える