字符串库函数的应用举例

来源:互联网 发布:三星打印机扫描软件 编辑:程序博客网 时间:2024/04/29 03:06

/*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;
}
0 0