TCP/IP test preparation: A simple timer-boost implementation, tcpboost
The TCP/IP experiment needs to view the results at the specified time. For the convenience of the experiment, a timer is made. The usage is as follows:
Enter timer in the command line.
Enter a number and time the corresponding number of seconds.
After the m number is input, the corresponding minute (decimal minutes are supported)
Enter q to exit.
When the Time is reached, there will be 3 beeps and the Time is up!
OK. displaying a progress bar is helpful.
The procedure is as follows:
Timer. cpp:
//g++ timer.cpp -o timer.exe -lboost_thread-mgw48-mt-1_56 -lboost_system-mgw48-1_56 -static#include <iostream>#include <boost/thread.hpp>#include <boost/progress.hpp>using namespace std;int main(){cout << "This is a simple timer.\n" << "Input an integer to time the seconds you want.\n" << "Input mDigits to time the minutes you want.\n" << "For example input 9 to time 9 seconds and\n" << "input m1.5 to time 1 minutes and 30 seconds.\n" << "input q to quit." << endl;char op;int seconds;double minutes;char beep = 7;for (;;){cout << ">> ";cin.sync();doop = cin.get();while (op == ' ' || op == '\t');if (op == 'q')return 0;if (op == 'm'){cin >> minutes;seconds = (int)(minutes * 60);} else if (isdigit(op)){cin.unget();cin >> seconds;} else if (op == '\n')continue;else {cout << "Lexical Error!!" << endl;continue;}boost::progress_display prog(seconds);for (int i = 0; i < seconds; ++i){boost::this_thread::sleep(boost::posix_time::seconds(1));++prog;}for (int i = 0; i < 3; ++i)cout << beep;cout << "Time is up!!!\n" << endl;}}