ofstream Odeint输出到txt文件

我尝试从ODEINT库运行此示例以解决ODE。它运行得很好,但是我不想将结果显示在屏幕上,而是想将它们写到文件中。我将此ofstream添加到write_cout函数下的代码中,但它仅将结果的最后一行写入文件,而不是全部。您对此有任何想法吗?谢谢

#include <iostream>
#include <boost/numeric/odeint.hpp>
#include <fstream>

using namespace std;
using namespace boost::numeric::odeint;


void rhs( const double x , double &dxdt , const double t )
{
dxdt = 3.0/(2.0*t*t) + x/(2.0*t);
}

void write_cout( const double &x , const double t )
{
cout << t << '\t' << x << endl;
cout<<"alo"<<endl;

ofstream buckyFile ("tuna.txt");
buckyFile<<t <<'\t'<<x<<endl;

}

// state_type = double
typedef runge_kutta_dopri5< double > stepper_type;

int main()
{
double x = 0.0;
integrate_adaptive( make_controlled( 1E-12 , 1E-12 , stepper_type() ) ,
                    rhs , x , 1.0 , 10.0 , 0.1 , write_cout );
}
眼睛的树
ofstream buckyFile ("tuna.txt");

tuna.txt每次输入该功能都会打开一个新文件,从而覆盖以前的功能。

快速解决方法是使用

static ofstream buckyFile ("tuna.txt");

反而。

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

ofstream:无法打开文件

来自分类Dev

C++ ofstream 输出文件不等于输出到文件

来自分类Dev

C ++ ofstream输出到图像文件在Windows上写入不同的数据

来自分类Dev

使用ofstream附加到文件

来自分类Dev

std :: ofstream不写入文件

来自分类Dev

C ++使用ofstream写入文件

来自分类Dev

C ++缩进输出类继承ofstream

来自分类Dev

cin / ofstream的不同输出格式

来自分类Dev

使用sstream in在ofstream中提供输出文件的名称

来自分类Dev

使用ofstream的日志文件中的日期

来自分类Dev

ofstream-将元素写入文件-C ++

来自分类Dev

ofstream-将元素写入文件-C ++

来自分类Dev

Ofstream创建但不会写入文件

来自分类Dev

每次迭代都会覆盖 ofstream 文件

来自分类Dev

ofstream输出字符串/字符且不加倍

来自分类Dev

在C ++中输出ofstream的filebuf *有什么作用?

来自分类Dev

为什么在使用ofstream时我的NSString变量输出“ 1”?

来自分类Dev

使用ofstream打开文件时设置文件权限

来自分类Dev

ofstream创建文件,但不使用C ++写入文件

来自分类Dev

std :: ofstream打开文件并替换为特定偏移量

来自分类Dev

ofstream(C ++)不会创建文件(权限被拒绝)

来自分类Dev

如何使用(整数类型)变量名创建ofstream文件?

来自分类Dev

从std :: ofstream逐行读取(但不是从文件读取)

来自分类Dev

std :: ofstream无法将std :: string写入文件

来自分类Dev

ofstream 在请求其内容之前创建文件

来自分类Dev

ofstream 创建一个文件但不写入

来自分类Dev

打开 ofstream 文件时 cin 和 cout 会做什么?

来自分类Dev

为什么 ofstream::write 在文件末尾添加额外的字节?

来自分类Dev

在 C# 中读取 C++ ofstream 写入的文件

Related 相关文章

热门标签

归档