关于string 的函数

#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main()
{
    string a;
    a = "123456";

    int index;
    // str.find(),如果是字符,返回该字符在母字符串中的坐标
    //            如果是字符串,返回字符串的首字符在母字符串的坐标
    // 如果查找不到,返回 -1.
    index = a.find("34");
    cout << index << endl;

    index = a.find('2');
    cout << index << endl;

    // substr(a,b) 从下标为 a 开始截取 长度为 b 的字符串,
    // substr(a)   从下标为 a 开始截取到末尾的字符串。
    a = a.substr(0,0);
    cout << a << endl;

    return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_41003528/article/details/81140902
今日推荐