STD: String addition Problem

Source: Internet
Author: User

Today, I encountered a weird problem. When I used eclipse to debug C ++ programs in Linux, the compilation was successful, but I couldn't go anywhere after a single step, the phenomenon is very random. The same code is completely correct in windows. By gradually commenting on the code, it is possible that multiple variables of the STD: string type are added consecutively, for example:
STD: String strwordsort = m_stroutpath + cutil: separator () + total_wordsort_file;
STD: String strscoresort = m_stroutpath + cutil: separator () + total_scoreorts_file;
STD: String strfilebad = m_stroutpath + cutil: separator () + bad_score_file;
STD: String strfilestatic = m_stroutpath + cutil: separator () + statistics_file;

However, it was found that sometimes only STD: String strwordsort = m_stroutpath + cutil: separator () + total_wordsort_file; is used, and sometimes it goes to STD: String strfilestatic = m_stroutpath + cutil :: separator () + statistics_file. Then I wondered whether the problem of adding the macro was not a problem, so I changed it:

STD: String strwordsort = m_stroutpath + cutil: separator () + "XX ";
STD: String strscoresort = m_stroutpath + cutil: separator () + "XX ";
STD: String strfilebad = m_stroutpath + cutil: separator () + "XX ";
STD: String strfilestatic = m_stroutpath + cutil: separator () + "XX ";

And then change it:

STD: String strwordsort = m_stroutpath + cutil: separator (); strwordsort + = total_wordsort_file;
STD: String strscoresort = m_stroutpath + cutil: separator (); strscoresort + = total_scoreorts_file;
STD: String strfilebad = m_stroutpath + cutil: separator (); strfilebad + = bad_score_file;
STD: String strfilestatic = m_stroutpath + cutil: separator (); strfilestatic + = statistics_file;

If the problem is solved, consider whether the initial value must be defined first, and whether many strings cannot be added when the initial value is defined, and then change:

STD: String strwordsort, strscoresort, strfilebad, strfilestatic;
Strwordsort = m_stroutpath + cutil: separator () + total_wordsort_file;
Strscoresort = m_stroutpath + cutil: separator () + total_scoreorts_file;
Strfilebad = m_stroutpath + cutil: separator () + bad_score_file;
Strfilestatic = m_stroutpath + cutil: separator () + statistics_file;

Well, after definition, it's okay to add multiple strings in a row, but why is the STD: string still not clear? I need to study it again and write it down as a question first. STD: The use of string in Linux/Windows is different. It is better to define it before adding and assigning values to multiple strings.

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.