逐步阅读txt文件 [英] read txt file step by step

查看:73
本文介绍了逐步阅读txt文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有一个带有时间序列数据的txt文件.因此,要编写一个从文件中读取但分段的代码,即它将数据读取到某个点,然后计算一个值,然后从停止点到另一个点开始读取数据,然后代码再次进行计算等等,依此类推...我搜寻了,但找不到任何线索...

欢迎每个帖子!

10x!

Hi,

I have a txt file with time series data. So want to write a code which reads from the file but in pieces i.e. It reads the data to a certain point then it computes a value, then it starts reading the data from the point where it stopped to anothepoint, the code does the computation again and so on and so on... I gogoled but I couldnot find any clue how to start...

Every post is welcomed!

10x!

推荐答案

以下是一些入门知识.这段代码将逐行读取文本文件".

int main()
{
    std :: ifstream istrm("MyFile.txt");
    std :: string line;
    while(std :: getline(istrm,line))
    {
        //使用line
    }
   返回0;
}
Here is something to get you started. This code will read a text file line by line"

int main()
{
    std::ifstream istrm("MyFile.txt");
    std::string line;
    while (std::getline(istrm, line))
    {
        // work with line
    }
    return 0;
}


这篇关于逐步阅读txt文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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