So I am trying to write a simple program that takes the time input by the user, and calculates the angles between and around the hands of an analog clock. I have run the program without parsing and 2 separate inputs but I wanted to parse the time at the colon (say, 12:35) and set the left side to an hour variable and the right side to a minutes variable. However, reading examples is hard when you don't know what some of the lines of code mean. Would somebody help me with an example and explain what each line is doing and why use that method?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
This is what you are looking for:
string time = "12:35";
unsigned int hour, minutes;
sscanf(time.c_str(), "%2d:%2d", &hour, &minutes);
cout << "Hour: " << hour << endl;
cout << "Minutes: " << minutes << endl;
回答2:
Are you looking for something like this:
unsigned int hours;
unsigned int minutes;
char colon;
std::cin >> hours >> colon >> minutes;
It inputs the hours first, then the colon character, then the minutes.