C++字符串操作
来源:互联网 发布:男装淘宝店 编辑:程序博客网 时间:2024/06/18 14:33
1. strcat——字符串连接
1 #include <iostream> 2 using namespace std; 3 4 int main(){ 5 6 char str[15] = "abcd"; 7 char str1[] = "abc"; 8 strcat(str, str1); 9 cout<<str<<endl;10 11 system("pause");12 return 0;13 }
※注意点,第一个字符串数组要足够大,否则会有越界问题。
2. strcpy——字符串拷贝
1 #include <iostream> 2 using namespace std; 3 4 int main(){ 5 6 char str[15] = "abcd"; 7 char str1[] = "abc"; 8 strcpy(str, str1); 9 cout<<str<<endl;10 11 system("pause");12 return 0;13 }
※注意点,第一个字符串数组要足够大,否则会有越界问题。另外第二个参数可以不是数组,可以是字符。
3. strcmp——字符串比较函数
1 #include <iostream> 2 using namespace std; 3 4 int main(){ 5 6 char str[15] = "abcd"; 7 char str1[] = "abc"; 8 if(0 == strcmp(str, str1)){ 9 cout<<"Equal."<<endl;10 }else{11 cout<<"Unequal."<<endl;12 }13 14 system("pause");15 return 0;16 }
※注意点,前者大,返回1;后者大,返回-1;相等,返回0。
4. strupr——小写转大写
1 #include <iostream> 2 using namespace std; 3 4 int main(){ 5 6 char str[15] = "abcdf"; 7 char str1[] = "abcde"; 8 strupr(str); 9 cout<<str<<endl;10 11 system("pause");12 return 0;13 }
5. strlwr——大写转小写
1 #include <iostream> 2 using namespace std; 3 4 int main(){ 5 6 char str[15] = "AASdf"; 7 strlwr(str); 8 cout<<str<<endl; 9 10 system("pause");11 return 0;12 }
6. strlen——获取字符串长度
1 #include <iostream> 2 using namespace std; 3 4 int main(){ 5 6 char str[15] = "AASdf"; 7 cout<<strlen(str)<<endl; 8 9 system("pause");10 return 0;11 }
0 0
- C字符串操作:字符串反转
- 字符串操作--c语言
- C语言字符串操作
- C字符串操作函数
- c操作翻转字符串
- C字符串操作函数
- c 字符串操作
- C语言 -- 字符串操作
- C 字符串操作
- C/C++字符串操作
- C字符串操作函数
- C语言字符串操作
- C中字符串操作
- C语言字符串操作
- C 字符串操作
- 字符串操作 c
- C - char字符串操作
- C语言字符串操作
- spring mvc搭建基本示例遇到的怪异问题及解决方法
- 【Android】Android中ContentProvider组件详解
- mysql中的left join用法 (及多条件查询
- 非阻塞socket服务器示例
- IOS 资料
- C++字符串操作
- 【深入浅出ios开发】UIActionSheet
- 实现一个最小栈的push(int x),pop(),top(),min()方法,要求都是常量时间
- setClickable(false)不起作用
- HDU4664
- 山寨版至理名言
- 什么是MapReduce?
- SQL Server 2008中SQL应用系列及BI学习笔记系列--目录索引
- 【Android动画】之Tween动画 (渐变、缩放、位移、旋转)