計算結果MPFR
をファイルに出力したいのですが、方法がわかりません。MPFR
高精度の浮動小数点演算を行うために使用されます。数値を印刷するmpfr_t
には、次の関数を使用します。
size_t mpfr_out_str (FILE *stream, int base, size t n, mpfr t op, mp rnd t rnd)
私の問題は、FILE*
オブジェクトと、それらがオブジェクトにどのように関連しているかを理解していないことだと思いfstream
ます。
行を変更my_file
すると、期待どおりに番号が画面に出力されますが、ファイルに取得する方法がわかりません。mpfr_out_str
stdout
#include <mpfr.h>
#include <iostream>
#include <fstream>
using namespace std;
int main() {
mpfr_t x;
mpfr_init(x);
mpfr_set_d(x, 1, MPFR_RNDN);
ofstream my_file;
my_file.open("output.txt");
mpfr_out_str(my_file, 2, 0, x, MPFR_RNDN);
my_file.close();
}