在24小时C+&#x2B中24小时后解析自动文件.txt。

发布于 2025-01-27 18:51:46 字数 630 浏览 2 评论 0原文

我有一个项目,我是C ++的新手 好吧,我必须解析一个file.txt,其中包含ATM中的交易信息。并且有名为交易日期的文件。 例如,文件(20211102.TXT)是一个文件,它具有在02/11/2021中创建的所有信息。 因此,午夜后创建另一个文件。 !!我的对象是:每天我都必须从前一天解析文件。 我尝试了一个生成昨天日期的函数。 我必须使用它,但我不知道 - 在

中解析文件的功能

void parse()
{
    ifstream file1("20211120.jrn");
    string str;
    if(file1.is_open())
    {
        while (getline(file1, str))
        {
            cout << str << "\n";
        }
        file1.close();
        cout << "PARSING FIRST JOURNAL" << endl;
    }
    else
        cout <<"File not found " << endl;

    file1.close();
}

我希望清楚的文件 。 先感谢您。

I have a project and I'm new to C++
Well I have to parse a file.txt that contains transaction informations in an ATM. And there is files named as the date of the transactions.
For example the file (20211102.txt) is a file that has all the informations, created in 02/11/2021.
So after midnight another file is being created .
!! My Objectif is : Every day I have to parse the file from the day before.
I have tried a function that generate the date of yesterday.
I have to use it But I don"t know how

-Here is the function of parsing the file

void parse()
{
    ifstream file1("20211120.jrn");
    string str;
    if(file1.is_open())
    {
        while (getline(file1, str))
        {
            cout << str << "\n";
        }
        file1.close();
        cout << "PARSING FIRST JOURNAL" << endl;
    }
    else
        cout <<"File not found " << endl;

    file1.close();
}

I hope it's clear .
Thank you in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

这个俗人 2025-02-03 18:51:46

这个问题,您可以做类似的事情:

#include <chrono>
#include <ctime>
#include <sstream>
#include <iomanip>
#include <string>
#include <iostream>

std::string return_current_time_and_date() {
    using namespace std::chrono_literals;
    auto now = std::chrono::system_clock::now();
    auto in_time_t = std::chrono::system_clock::to_time_t(now - 24h);

    std::stringstream ss;
    ss << std::put_time(std::localtime(&in_time_t), "%Y%m%d");
    return ss.str();
}

在您的用例(即格式,所以日期是昨天的日期)的地方。请参阅操作在这里

至于每天运行它,您必须让一些调度程序为您运行。我在Windows上对此并不熟悉,但是网站似乎就如何设置这样的工作提供了很好的建议。另外,这个问题可能是使用的。

As discussed in this question, you can do something like:

#include <chrono>
#include <ctime>
#include <sstream>
#include <iomanip>
#include <string>
#include <iostream>

std::string return_current_time_and_date() {
    using namespace std::chrono_literals;
    auto now = std::chrono::system_clock::now();
    auto in_time_t = std::chrono::system_clock::to_time_t(now - 24h);

    std::stringstream ss;
    ss << std::put_time(std::localtime(&in_time_t), "%Y%m%d");
    return ss.str();
}

where some things have been adapted for your use case (i.e. format and so the date is of yesterday). See operation here.

As to running it every day you'd have to have some scheduler run it for you. I am not that familiar with this on windows, but this website seems to offer good advice on how you can set up such a job. Alternatively this question, might be of use.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文