lundi 26 septembre 2016

c++ code that would keep the program running until i want it to

i am having a hard time searching on google because i don't know the right keyword yet.

basically i want a c++ code that when i run the program it will keep running until i close it.

so for example i have a text file , and every so often i would add something on the file. i want the program to keep running checking if the text changed

for loop only loops until a specific amount. i would like it to keep running for a specific time.

let us say contents of the text file is

1 2 3

then a simple code

vector<int> vec;
int temp;

ifstream x;
x.open ("test.txt",ios::in);
while(!eof)
{
x>>temp;
vec.push_back(temp)
}
x.close();

for(unsigned int i=0; i<vec.size(); i++)
cout<<vec[i]<<' ';

// some code to rerun the program again to check the file if it changed

it should output me

1 2 3

then let us say 5 minutes later(not closing the program)i would change the text file to 1 2 3 4

it should also update itself and output 1 2 3 4 without me closing and running the program again.

thank you.

Aucun commentaire:

Enregistrer un commentaire