1. 程式人生 > >字串庫函式的應用舉例

字串庫函式的應用舉例

/*C++中,string標頭檔案基本上已經包含在iostream中了。
但是,平時使用的時候建議加#include<string.h>

<string.h>是標準C提供的字元處理函式集。面向char  *

  */

#include <iostream>

//#include <string.h>
using namespace std;
void main()
{
const int n=100;
char a[n]="ABC",*p="DEF";
if (strcmp(a,p))//比較兩個字串
{
cout<<"兩個字串相同"<<endl;
}else
cout<<"兩個字串不相同"<<endl;
strcat(a,p);
cout<<"連線之後的字串是"<<a<<endl;
cout<<"連線之後的字串的有效長度是"<<strlen(a)<<endl;
char b[80];
strcpy(b,p);
cout<<"複製之後的字串是"<<b<<endl;
}