The program receives the following text 1:15.06.2016-14:47
Format: статус:дата-время
This all needs to be broken.
2 answers
Smash to what extent? By a separate figure, or on the status date time?
The easiest way is to use sscanf (or sscanf_s if you are bothered by security) - for example:
int main(int argc, const char * argv[]) { int status; char date[20], time[20]; if (3 != sscanf_s("1:15.06.2016-14:47","%d:%10s-%s",&status,date,20,time,20)) cout << "Error!\n"; else { cout << "Status: " << status << " Date: " << date << " Time: " << time << endl; } int D,M,Y,h,m; if (6 != sscanf_s("1:15.06.2016-14:47","%d:%d.%d.%d-%d:%d",&status,&D,&M,&Y,&h,&m)) cout << "Error!\n"; else { cout << "Status: " << status << " Date: " << D << " " << M << " " << Y << " Time: " << h << " " << m << endl; } } |
ValueTypeVector arr = split(a, ':');//Разбивка статуса for (const ValueType& it : arr) cout << it << " "; if (arr[0] == 1)//Проверка 1 аргумента { MessageBox(0, "1", 0, 0); } else { MessageBox(0, "0", 0, 0); } - If you only needed status, then why ask "this all needs to be broken"? :) Only status - but at least call
atoi:) - Harry
|
strtok(ala C-style ), or by means ofstd::regex(ala C ++ 11 ). - StateItPrimitive