The program receives the following text 1:15.06.2016-14:47
Format: статус:дата-время
This all needs to be broken.

  • one
    It is important for us that you yourself try to do this. Therefore, I will not do it for you, I will only tell you that the necessary result can be achieved, for example, by means of strtok (ala C-style ), or by means of std::regex (ala C ++ 11 ). - StateItPrimitive
  • 'strtok': This function or variable may be unsafe. Consider using strtok_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details. - Test11111
  • Fixed #define _CRT_SECURE_NO_WARNINGS - Test11111
  • Beat something like? One character at a time? By two? Something else? Well, if the format is fixed - the problem is solved by a pair of string functions and access to the elements of the line by indices. - Vladimir Martyanov
  • can your code show how you started doing this? - Saidolim

2 answers 2

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