BZ易风

导航

 

字串

#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
using namespace std;
#include <string>

/*
字串
string substr(int pos = 0, int n = npos) const;//返回由pos开始的n个字符组成的字符串
*/
void test01()
{
    string str = "abcde";
    string str2 = str.substr(1, 3);  //bcd
    cout << str2 << endl;

    string str3 = "zhangsan2@qq.com";
    int pos = str3.find('@');           //返回@位置
    string username = str3.substr(0, pos);
    cout << username << endl;
}

int main()
{
    test01();
    system("Pause");
    return 0;
}

结果:

 

posted on 2021-08-26 13:20  BZ易风  阅读(21)  评论(0编辑  收藏  举报