6_72.cpp

来自「C++语言程序设计案例教程,郑莉编的书」· C++ 代码 · 共 22 行

CPP
22
字号
#include <iostream>
#include <string>
using namespace std;
void DispInfo( const string & );
int main()
{  string str; cout << "Statistics before input:\n" << boolalpha; DispInfo( str );
   cout << "\nEnter a string: ";   cin >> str; 
   cout << "The string entered was: " << str;
   cout << "\nStatistics after input:\n";  DispInfo( str ); 
   str.resize( str.length() + 10 ); // 向str 中添加10 个元素
   cout << "\nStats after resizing by (length + 10):\n";   DispInfo( str );
   return 0;
} 
//输出字符串的特性
void DispInfo( const string &stringRef )
{  cout << "capacity: " 	<< stringRef.capacity() 
        << "\tmax size: " 	<< stringRef.max_size()
        << "\nsize: " 		<< stringRef.size() 
        << "\tlength: " 	<< stringRef.length()
        << "\tempty: " 		<< stringRef.empty();
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?