c++ 字符串拷貝以及合並


 

#include<iostream>
#include<string>
using namespace std;
class stringfun
{
    char name[20];
    public:
       void concatString(char a[],char b[])
       {
          strcat(a," ");
          strcat(a,b);
          strcpy(name,a);
       }
       void display()
       {
          cout<<"\nName : "<<name;
       }
};
int main()
{
    char str1[10],str2[10];

    stringfun sf;

    cout<<"Enter your name:";
    gets(str1);
    cout<<"Enter sir name:";
    gets(str2);
    sf.concatString(str1,str2);
    sf.display();
    return 0;
}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM