本文整理汇总了C++中MyString::reserve方法的典型用法代码示例。如果您正苦于以下问题:C++ MyString::reserve方法的具体用法?C++ MyString::reserve怎么用?C++ MyString::reserve使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MyString
的用法示例。
在下文中一共展示了MyString::reserve方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
MyString
MyString::EscapeChars(const MyString& Q, const char escape) const
{
// create a result string. may as well reserve the length to
// begin with so we don't recopy the string for EVERY character.
// this algorithm WILL recopy the string for each char that ends
// up being escaped.
MyString S;
S.reserve(Len);
// go through each char in this string
for (int i = 0; i < Len; i++) {
// if it is in the set of chars to escape,
// drop an escape onto the end of the result
if (Q.FindChar(Data[i]) >= 0) {
// this character needs escaping
S += escape;
}
// put this char into the result
S += Data[i];
}
// thats it!
return S;
}