I am writing an emulator for my course "Operating Systems". The problem is that we need to get all of our .job files (they are similar to the application programs that are served in the emulator) from STDIN and read them.
Call:
./RMMIX < aJob.job
I just use
while(getline(std::cin, line))
line by line. The problem is that if I donβt use anything for STDIN, then cin will wait for user input - NOT what I want. I need a program to recognize a lack of text in STDIN and stop working, and not wait for user input.
I decided that I could request the length as follows:
size_t beg = std::cin.tellg(); std::cin.seekg(0, std::ios_base::end); size_t end = std::cin.tellg(); std::cin.seekg(0, std::ios_base::beg);
and terminate if std :: cin is 0 in length.
Are there any other solutions? Is this a portable solution?
IAE
source share