Reading from timestamped .txt file

For the project that I am working on I need to be able to simulate information coming in o the program from a sensor every 10 seconds by using a .txt file since I wont have the ability to use sensors. I am unsure how I would go about creating a document that has the correct time stamps to do this and then what would be the correct code to pull this information in every 10 seconds.

Thanks in advance for the help.
do you have something like this in mind?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include <iostream>
#include <fstream>
#include <thread>
#include <string>

int main()
{
    using namespace std::chrono_literals;
    std::fstream inFile{"D:\\test.txt"};
    while (inFile)
    {
        std::this_thread::sleep_for(10s);
        //http://en.cppreference.com/w/cpp/thread/sleep_for
        std::string line{};
        getline(inFile, line);
        std::cout << line << "\n";
    }
}
/* .txt file:
hello world
this is
cpp
the most
wonderful programming
language in
the world
*/
Last edited on
I didn't really have much in mind to be honest. I really wasn't sure how how i was going to do it at all. I need the program to read a value in from the file every 10 seconds and then display a message based on parameters that were previously set in the program.
I don't know if it would be easier to read all the values from the text file in to a vector and then pull a value from the vector every 10 seconds and then make a decision depending on what the value is.
like i said i'm really struggling with what to do for this so whatever you guys got will be helpful
Topic archived. No new replies allowed.