如何在文本文件中保存实时数据 [英] How can I save real time data in a text file

查看:147
本文介绍了如何在文本文件中保存实时数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码



 if(StartMonitor)// StartMonitor 
{

TotalVoltage5s + = CalculatePower();
// TotalVoltage5s + = 20;
xx123 ++;

CString伤心;
m_power_edit.GetWindowText(伤心);

int num1 = _ttoi(悲伤);
if(xx123> = num1){
if(TotalTime> 19){

Power_Log_Chart.ClearChart();
TotalTime = 0;

}

CTime tm;
tm = CTime :: GetCurrentTime();
CString str = tm.Format(%X);
ostringstream os;
float ds =(float)atof((char *)(LPTSTR)(LPCTSTR)悲伤);
os<< TotalVoltage5s / DS;
ostringstream os1;
m_power_list.InsertColumn(Current_columns,,LVCFMT_CENTER,80,0);
m_power_list.SetItemText(0,Current_columns,str);
m_power_list.SetItemText(1,Current_columns,os.str()。c_str());
m_power_list.SetItemState(Current_columns,LVIS_SELECTED | LVIS_FOCUSED,LVIS_SELECTED | LVIS_FOCUSED);
m_power_list.EnsureVisible(Current_columns,FALSE);


Power_Log_Chart.SetXYValue(TotalTime,TotalVoltage5s / ds,TotalTime,0);
TotalTime ++;
TotalVoltage5s = 0;





简单地说,它采用Calculatepower()函数的计算值并每隔5秒显示一次结果使用Totalvoltage5s和TotalTime。我需要一种方法每隔19秒将这些数据保存在一个txt文件中。



我尝试过:



我试图使用FOR循环保存数据,但我一直收到错误。

解决方案

不需要for循环,下面的代码将保存我们在excel文件中的数据:



 std :: ofstream outfile; 
outfile.open(Real-Time.csv,std :: ios_base :: app);
outfile<< TotalTime<<,<< os.str()。c_str()<<,<< os1.str()。c_str()< < ENDL;
outfile.close();


此代码适用于我:





 std :: ofstream outfile; 
outfile.open(Real-Time.csv,std :: ios_base :: app);
outfile<< TotalTime<<,<< os.str()。c_str()<<,<< os1.str()。c_str()< < ENDL;


Hi, I have the following code

if (StartMonitor) //StartMonitor
{

    TotalVoltage5s += CalculatePower();
    //TotalVoltage5s += 20;
    xx123++;

    CString sad;
    m_power_edit.GetWindowText(sad);

    int num1 = _ttoi(sad);
    if(xx123 >= num1){
        if(TotalTime > 19){

            Power_Log_Chart.ClearChart();
            TotalTime = 0;

        }

        CTime tm;
        tm=CTime::GetCurrentTime();
        CString str=tm.Format("%X");
        ostringstream os;
        float ds= (float)atof((char *)(LPTSTR)(LPCTSTR)sad);
        os << TotalVoltage5s/ds;
        ostringstream os1;
        m_power_list.InsertColumn(Current_columns,"",LVCFMT_CENTER,80,0);
        m_power_list.SetItemText(0, Current_columns, str);
        m_power_list.SetItemText(1, Current_columns, os.str().c_str());
        m_power_list.SetItemState(Current_columns, LVIS_SELECTED|LVIS_FOCUSED, LVIS_SELECTED|LVIS_FOCUSED);
        m_power_list.EnsureVisible(Current_columns, FALSE);


        Power_Log_Chart.SetXYValue(TotalTime, TotalVoltage5s/ds, TotalTime, 0);
        TotalTime++;
        TotalVoltage5s = 0;



What it simply does, it takes the calculated value of Calculatepower() function and display the results in every 5 seconds using Totalvoltage5s and and TotalTime. I need a way to save these data in a txt file every 19 seconds.

What I have tried:

I have tried to save the data using a FOR loop but I keep getting an error.

解决方案

No need for a for loop, the following code will save the data for us in an excel file:

std::ofstream outfile;
outfile.open("Real-Time.csv", std::ios_base::app);
outfile<<TotalTime<<", "<<os.str().c_str()<<", "<<os1.str().c_str()<<endl;
outfile.close(); 


This code works for me:


std::ofstream outfile;
outfile.open("Real-Time.csv", std::ios_base::app);
outfile<<TotalTime<<", "<<os.str().c_str()<<", "<<os1.str().c_str()<<endl; 


这篇关于如何在文本文件中保存实时数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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