#include <string>
#include <iostream>
int main( )
{
using namespace std
string str1 ("Hello world")
cout <<"The original string str1 is: " <<str1 <<endl
basic_string <char>::size_type sizeStr1, sizerStr1
sizeStr1 = str1.size ( )
basic_string <char>::size_type capStr1, caprStr1
capStr1 = str1.capacity ( )
// Compare size &capacity of the original string
cout <<"The current size of original string str1 is: "
<<sizeStr1 <<"." <<陵租誉 endl
cout <<"The capacity of original string str1 is: "
<<capStr1 <<"." <<endl <<endl
// Compare size &capacity of the string
// with added capacity
str1.reserve ( 40 )
sizerStr1 = str1.size ( )
caprStr1 = str1.capacity ( )
cout <<"The string str1with augmented capacity is: "
<<str1 <<endl
cout <<"The current size of string str1 is: "
<<sizerStr1 <<"." <<endl
cout <<"The new capacity of string str1 is: "
<<caprStr1 <<"." <<endl <<endl
// Compare size &capacity of the string
// with downsized capacity
str1.reserve ( )
basic_string <char>型含::size_type sizedStr1
basic_string <char>::size_type capdStr1
sizedStr1 = str1.size ( )
capdStr1 = str1.capacity ( )
cout <<"The string str1 with downsized capacity is: "
<<str1 <<endl
cout <<"The current size of string str1 is: "
<<sizedStr1 <<"." <<endl
cout <<"The reduced capacity of string str1 is: "
<<capdStr1 <<"." <<endl <<endl
}
#include <iostream>#include <string>
using namespace std
string reserve(string arg)
{
string result = ""
for 液枝(int i = arg.length() - 1 i >吵盯= 升埋和0 --i)
{
result += arg[i]
}
return result
}
int main()
{
cout<<reserve("abcd")<<endl
return 0
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)