At the beginning, I started to contact C ++. I don't know much about it. Let's look at the Code provided by the boss. Here year = atoi (dateStr. substr (0, 4). c_str (); it's in the fog.
Year = atoi (dateStr. substr (0, 4). c_str ());
It contains three functions: atoi (), substr (), and c_str ().
Baidu:
The prototype of the atoi () function is int atoi (char * str). It is used to convert a string into an integer. str is a string to be converted into an integer. if the conversion succeeds, the converted integer is returned. If the conversion fails, 0 is returned.
The prototype of the substr () function is basic string: substr (string, start, length). You can also move the string to the outside, which is string & a,. substr (start, length), where a is the string to be intercepted, start indicates the first digit from the truncation, and length indicates the truncation length, such as string & a = "hello world ", then. substr (6, 5) = world.
The prototype of the c_str () function is const char * c_str (). to convert a string object to a char * object, c_str () provides this method, it returns a pointer that the client program can read and cannot modify to a character array.
So year = atoi (dateStr. substr (0, 4 ). c_str () is used to intercept the string-type object dateStr, convert it to a char * object, and then convert the string to an integer, assign year (year is int type ).