string类的常用的几个小东西find,substr
2016-05-13 14:43
232 查看
头文件:
定义:
#include<iostream> #include<string>
定义:
string ss;
#include<iostream> #include<string>
int main()
{
string ss;
while(1)
{
getline(cin,ss);
cout<<ss<<endl;
int a;
a=ss.find('a');
printf("a=%d\n",a);
string temp;
temp=ss;
cout<<temp<<endl;
temp=ss.substr(2,3); //在ss中的第2个(包括第二个)开始的3个字符
cout<<temp<<endl;
temp=ss+ss.substr(2,3); //ss+在ss中的第2个(包括第二个)开始的3个字符
cout<<temp<<endl;
temp=ss+ss.substr(2); //ss+在ss中的第2个(包括第二个)开始的以后全部
cout<<temp<<endl;
}
return 0;
}
相关文章推荐
- “百度搜索框提示”代码
- 设计模式之观察者模式
- android-async-http开源项目介绍及使用方法
- 穿过已知点画平滑曲线(3次贝塞尔曲线)
- Elisp 入门笔记(2)
- HTML5 LocalStorage 本地存储
- JavaScript——3(事件处理与实用范例)
- maven eclipse(1)搭建
- Spark SQL性能优化
- Android之dialog
- nutch源代码阅读心得
- 使用递归高斯滤波器实现快速高斯模糊
- 在CMD下用java命令出现“找不到或无法加载主类”问题
- Caffe 使用教程1 - 从数据训练到在线服务概览
- SQL测试题
- equals和hashCode方法详解
- 持续集成工具FinalBuilder使用心得
- java-web项目跨域的问题
- 通俗易懂之epoll--转自”知乎“
- TableView跳转到指定的cell