⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fig19_05.cpp

📁 经典vc教程的例子程序
💻 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 + -