欧美大屁股bbbbxxxx,狼人大香伊蕉国产www亚洲,男ji大巴进入女人的视频小说,男人把ji大巴放进女人免费视频,免费情侣作爱视频

歡迎來到入門教程網(wǎng)!

C語言

當(dāng)前位置:主頁 > 軟件編程 > C語言 >

將字符串str1復(fù)制為字符串str2的三種解決方法

來源:本站原創(chuàng)|時間:2020-01-10|欄目:C語言|點(diǎn)擊: 次

1.自己編寫函數(shù),將兩個字符串進(jìn)行復(fù)制

復(fù)制代碼 代碼如下:

#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!='\0';p1++,p2++){
  *p2=*p1;
 }
 *p2='\0';
}

2.使用函數(shù)庫重的strcpy函數(shù)
復(fù)制代碼 代碼如下:

#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.定義兩個字符串變量,然后直接進(jìn)行賦值
復(fù)制代碼 代碼如下:

#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;
}

網(wǎng)頁制作CMS教程網(wǎng)絡(luò)編程軟件編程腳本語言數(shù)據(jù)庫服務(wù)器

如果侵犯了您的權(quán)利,請與我們聯(lián)系,我們將在24小時內(nèi)進(jìn)行處理、任何非本站因素導(dǎo)致的法律后果,本站均不負(fù)任何責(zé)任。

聯(lián)系QQ:835971066 | 郵箱:835971066#qq.com(#換成@)

Copyright © 2002-2020 腳本教程網(wǎng) 版權(quán)所有