string类

来源:互联网 发布:哪个软件找工作靠谱 编辑:程序博客网 时间:2024/06/13 15:44

最后一个字符:

find的使用
<pre class="cpp" name="code">#include <iostream>#include <string>using namespace std;void main(){string str1 = "hello world";string str2 = str1.substr(2, 3);//下标为2开始截取3个字符cout << str2 << endl;system("pause");}


substr使用方法
string str1 = "hello world";int a = str1.find("hello");int b = str1.find("l",4);//从下标4开始寻找"l",返回下标

string转换为int
string a = "123456";const char *b = a.c_str();int c = atoi(b);


0 0
原创粉丝点击