📄 fig19_05.cpp
字号:
// Fig. 19.5: fig19_05.cpp
// Demonstrating functions related to size and capacity
#include <iostream>
#include <string>
using namespace std;
void printStats( const string & );
int main()
{
string s;
cout << "Stats before input:\n";
printStats( s );
cout << "\n\nEnter a string: ";
cin >> s; // delimited by whitespace
cout << "The string entered was: " << s;
cout << "\nStats after input:\n";
printStats( s );
s.resize( s.length() + 10 );
cout << "\n\nStats after resizing by (length + 10):\n";
printStats( s );
cout << endl;
return 0;
}
void printStats( const string &str )
{
cout << "capacity: " << str.capacity()
<< "\nmax size: " << str.max_size()
<< "\nsize: " << str.size()
<< "\nlength: " << str.length()
<< "\nempty: " << ( str.empty() ? "true": "false" );
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -