Std: string, pants fart stdstring
A daily struggle with c # Forces c ++ programmers to change their previous code and find the following lines.
Char szPath [MAX_PATH] = {0 };
GetModuleFileNameA (NULL, szPath, sizeof (szPath ));
Std: string strPath = szPath;
Std: string strDir = strPath. substr (0, strPath. find_last_of ('\\'));
I feel uncomfortable. Why are there char arrays and strings? Is it better to use strings.
The following code is changed:
Std: strPath;
StrPath. reserve (MAX_PATH );
GetModuleFileNameA (NULL, & strPath [0], MAX_PATH );
Std: string strDir = strPath. substr (0, strPath. find_last_of ('\\'));
Okay, I have finished modifying. The Nima function has changed... you know .......
StrDir is empty.
For some reason, although there is content in strPath, the API will not assign a value to the size of string.
If you want to use string to replace the char array correctly, you can only use the following method.
Std: strPath;
StrPath. resize (MAX_PATH, 0 );
GetModuleFileNameA (NULL, & strPath [0], strPath. size ());
StrPath. asign (strPath. c_str (); // assign a value again.
This... isn't it because of dragging your pants?
Zookeeper
Std: string
Substr (n) starts from the nth character to the last
Substr (m, n) from m to n
If the endpoint does not contain the endpoint, check msdn again. I remember it was closed before and after it was enabled.
C ++ question std: What does string & strOut mean?
Std is a system namespace (for more information about namespaces, see baike.baidu.com/view/159924.htm? Fr = ala0_1), string is a variable type, which is included in the std namespace. If you declare a header file with using namespace std; in later programs, you do not need to write the std: statement like this. As for & strOut, strOut is a variable name, and adding & is a reference, I don't know if you know what to cite. For example,
Int a = 1
Int & B =;
B can be understood as the outer number of a, occupying the same memory space, cout <a <B; the structure is 1