我想打印使用MPFR
的計算結果到文件,但我不知道如何。 MPFR
用於高精度地進行浮點運算。要打印mpfr_t
號所使用的功能:從MPFR打印到文件
size_t mpfr_out_str (FILE *stream, int base, size t n, mpfr t op, mp rnd t rnd)
我想我的問題是,我不明白FILE*
對象以及它們如何與fstream
對象。
如果我在mpfr_out_str
行stdout
改變my_file
然後爲我所希望的,但我不知道如何得到它到文件的數量將打印到屏幕上。
#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();
}