1. Write your own function and copy two strings
Copy Code code as follows:
#include <iostream>
using namespace Std;
int main () {
Char str1[]= "I love china!", str2[20];
void Strcpy (char *p1,char *p2);
Strcpy (STR2,STR1);
cout<< "STR1:" <<str1<<endl;
cout<< "str2:" <<str2<<endl;
return 0;
}
void Strcpy (char *p2,char *p1) {
int i=0;
for (; *p1!= ';p 1++,p2++) {
*P2=*P1;
}
*p2= ' ";
}
2. strcpy function with function library weight
Copy Code code as follows:
#include <iostream>
using namespace Std;
int main () {
Char str1[]= "I love china!", str2[20];
strcpy (STR2,STR1);
cout<< "STR1:" <<str1<<endl;
cout<< "str2:" <<str2<<endl;
return 0;
}
3. Define two string variables, then assign directly
Copy Code code as follows:
#include <iostream>
#include <string>
using namespace Std;
int main () {
String str1= "I Love china!", str2;
STR2=STR1;
cout<< "STR1:" <<str1<<endl;
cout<< "str2:" <<str2<<endl;
return 0;
}