基于c++浅谈string类函数
来源:互联网 发布:打击网络犯罪宣传资料 编辑:程序博客网 时间:2024/06/06 08:30
#include <iostream>
#include <string>
using namespace std;
int main()
{
string str1(5, 'c');
string str2("Now is the time ...");
string str3(str2, 11, 4);
string str4("hello world", 6);
cout << str1 << endl;
cout << str2 << endl;
cout << str3 << endl;
cout << str4 << endl;
string str5 = str1 + str2;
cout << str5 << endl;
cout << "下面开始字符串比较" << endl;
cout << (str1 == str2) << endl;
cout << (str1 != str2) << endl;
cout << (str1 > str2) << endl;
cout << (str1 < str2) << endl;
cout << str1[3] << endl;
cout << "其他方法调用" << endl;
cout << str1.length() <<endl; //string类型求长度
cout << (str2.find('1') == string::npos) << endl; //寻找字符串中是否有某个字符
cout << str2.at(3) << endl; //取其中的第4个元素
cout << str2.length() << "," << str2.capacity() << endl;
string first("This comes first");
string second("And this is second");
first.swap(second);
cout << first << endl;
cout << second << endl;
cout << str4.rfind("hello") << endl;
return 0;
}
#include <string>
using namespace std;
int main()
{
string str1(5, 'c');
string str2("Now is the time ...");
string str3(str2, 11, 4);
string str4("hello world", 6);
cout << str1 << endl;
cout << str2 << endl;
cout << str3 << endl;
cout << str4 << endl;
string str5 = str1 + str2;
cout << str5 << endl;
cout << "下面开始字符串比较" << endl;
cout << (str1 == str2) << endl;
cout << (str1 != str2) << endl;
cout << (str1 > str2) << endl;
cout << (str1 < str2) << endl;
cout << str1[3] << endl;
cout << "其他方法调用" << endl;
cout << str1.length() <<endl; //string类型求长度
cout << (str2.find('1') == string::npos) << endl; //寻找字符串中是否有某个字符
cout << str2.at(3) << endl; //取其中的第4个元素
cout << str2.length() << "," << str2.capacity() << endl;
string first("This comes first");
string second("And this is second");
first.swap(second);
cout << first << endl;
cout << second << endl;
cout << str4.rfind("hello") << endl;
return 0;
}
阅读全文
0 0
- 基于c++浅谈string类函数
- 浅谈C++string类
- C++string类常用函数
- C++string类常用函数
- C++string类常用函数
- C++string类常用函数
- C++string类常用函数
- C++string类常用函数
- C++string类常用函数
- C++string类常用函数
- C++string 类常用函数
- C++string类常用函数
- C++string类常用函数
- C++string类常用函数
- C++string类常用函数
- C++STRING类常用函数
- C++string类常用函数
- C++string类常用函数
- iOS 引入framework的常见问题和原理
- 两个进程之间的通信
- 数据结构(排序)
- bzoj 4589: Hard Nim 快速沃尔什变换
- MysqlServer2008R2数据库用法
- 基于c++浅谈string类函数
- Cocos2d-x项目创建方式
- Windows下更改Python默认版本的方法
- 数组
- arm的一些概念(ARM7、Cortex-M的区别)
- (一)洞悉linux下的Netfilter&iptables:什么是Netfilter
- BeanUtils的简单认识
- Python自然语言处理 2 获得文本语料和词汇资源
- 机器学习基石-10-3-Gradient of Logistic Regression Error