子 #include <iostream> using namespace std void maino char s1[20J= Hello”; char s2 20=world char s3 20 strcpy(s3, Ssl) ∥字符串拷贝 cout<<s3<<endl strcat(s3, s2 ∥字符串连接 cout<<s3<<endl
例子: #include <iostream> using namespace std; void main() { char s1[20]=”Hello”; char s2[20]=”world”; char s3[20]; strcpy(s3,s1); //字符串拷贝 cout<<s3<<endl; strcat(s3,s2); //字符串连接 cout<<s3<<endl; }
例子:添加运算符重载 #include <string> #include < iostream> using namespace std void maino string sI=Hello string s2=world string s3 S3=SI ∥字符串拷贝 cout<<s3<<endl S3=SI+S2 ∥字符串连接 cout<<s3<<endl
例子:添加运算符重载 #include <string> #include <iostream> using namespace std; void main() { string s1="Hello"; string s2="world"; string s3; s3=s1; //字符串拷贝 cout<<s3<<endl; s3=s1+s2; //字符串连接 cout<<s3<<endl; }
10.2运算符重载的限制
10.2 运算符重载的限制
10.2运算符重载的限制 ◆1、重载运算符时,重载运算符的运算顺序和优先级不 变 ◆2、不能创造新运算符 ◆3、规定不能重载的运算符: Operator Name 类属关系运算符 成员指针运算符 #儿:* 作用域运算符 条件运算符 编译预处理符号 szeo0取数据类型的长度
10.2 运算符重载的限制 1、重载运算符时,重载运算符的运算顺序和优先级不 变。 2、不能创造新运算符 3、规定不能重载的运算符: Operator Name . 类属关系运算符 # 编译预处理符号 .* 成员指针运算符 :: 作用域运算符 ? : 条件运算符 sizeof() 取数据类型的长度
10.3运算符重载的语法
10.3 运算符重载的语法