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

📄 fig19_01.cpp

📁 经典vc教程的例子程序
💻 CPP
字号:
// Fig. 19.1: fig19_01.cpp
// Demonstrating string assignment and concatenation
#include <iostream>
#include <string>
using namespace std;

int main()
{
   string s1( "cat" ), s2, s3;

   s2 = s1;          // assign s1 to s2 with =
   s3.assign( s1 );  // assign s1 to s3 with assign()
   cout << "s1: " << s1 << "\ns2: " << s2 << "\ns3: "
        << s3 << "\n\n";

   // modify s2 and s3 
   s2[ 0 ] = s3[ 2 ] = 'r';

   cout << "After modification of s2 and s3:\n"
        << "s1: " << s1 << "\ns2: " << s2 << "\ns3: ";             

   // demonstrating member function at()
   int len = s3.length();
   for ( int x = 0; x < len; ++x ) 
      cout << s3.at( x );

   // concatenation
   string s4( s1 + "apult" ), s5;  // declare s4 and s5

   // overloaded +=
   s3 += "pet";             // create "carpet"
   s1.append( "acomb" );    // create "catacomb"

   // append subscript locations 4 thru the end of s1 to
   // create the string "comb" (s5 was initially empty)
   s5.append( s1, 4, s1.size() );
                                 
   cout << "\n\nAfter concatcenation:\n" << "s1: " << s1 
        << "\ns2: " << s2 << "\ns3: " << s3 << "\ns4: " << s4 
        << "\ns5: " << s5 << endl;
   
   return 0;
}

⌨️ 快捷键说明

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