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 you have put your pants on?
Zookeeper