STD: String

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.