C++字符串相关操作函数
2016-05-06 17:25
525 查看
#include <IOSTREAM> using namespace std; /*字符串相关操作函数:strcat、strcpy、strcmp、strupr、strlwr、strlen*/ void main() { char str0[100] = "This is a C++ program!"; char str1[10] = "So what!"; //strcat 字符串连接函数 strcat(str0,str1); cout<<"str0:"; puts(str0); //strcpy 字符串复制函数 strcpy(str0,str1); cout<<"str0:"; cout<<str0<<endl; cout<<"str0[12]:"<<str0[12]<<endl; //strcmp 字符串比较函数 char str2[] = "So whas!"; cout<<strcmp(str1,"So what!")<<endl; cout<<strcmp(str1,str2)<<endl; cout<<strcmp(str1,"So waat!adff")<<endl; cout<<strcmp(str1,"So wkat!")<<endl; cout<<strcmp(str1,"So what!adff")<<endl; //strupr 字符串全部转化为大写 strupr(str2); puts(str2); //strlwr 字符串全部转化为小写 strlwr(str2); puts(str2); //strlen 字符串长度(不包括字符串结束符'\0') cout<<"str2的长度:"<<strlen(str2)<<endl; } /* str0:This is a C++ program!So what! str0:So what! str0[12]:+ 0 1 1 -1 -1 SO WHAS! so whas! str2的长度:8 Press any key to continue */
相关文章推荐
- c++ 如何把this指针传入成员函数 像全局函数一样调用成员函数
- vector删除指定元素
- C语言中extern的用法
- leetcode_169_Majority Element(C++)(easy)
- c++
- More Effective C++----(18)分期摊还期望的计算
- C++实现线索化二叉树
- C++模板
- C++ 子类继承带参的父类构造函数应该怎么写
- 【C语言】过滤字符串非字母的字符并统计字母数
- C++基础知识汇总
- C语言的运行环境有哪些?哪些是值得推荐的?
- C++11中的线程同步(简单测试)
- C++中继承,虚函数的调用问题
- C++:标准库函数(sort)
- [转]用C/C++扩展PHP详解
- 二叉排序树C语言实现一
- C++中的构造函数学习
- c++ unique函数返回值
- C语言位操作\进制转换(十四)