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.
#include <iostream>
#include <fstream>
#include <thread>
#include <string>
int main()
{
usingnamespace 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
*/
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