413.cpp

来自「C++实训教程」· C++ 代码 · 共 35 行

CPP
35
字号
//413.cpp   使用string类的接口
#include <iostream.H>
#include <cstring.H>
main(void)
{
   string s1("abcdefghijk"), s2("1234567890"), s3,s4,s5;           // copy

   s3=s1+s2;
   cout << s3 <<endl;
   cout << "s3 length=" << s3.length()<< endl;

   size_t pos;
   pos=s3.find(s2);
   cout << "The find Position is " << pos << endl;

   s4=s3;
   if (s4==s3) cout << " s4==s3 is true\n";

   s4.prepend("====");
   cout << s4 <<endl;

   s1.append(s2,3); //append from s2[3]
   cout << s1 <<endl;
	return(0);
}
/*
abcdefghijk1234567890
s3 length=21
The find Position is 11
 s4==s3 is true
====abcdefghijk1234567890
abcdefghijk4567890

*/

⌨️ 快捷键说明

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