STL容器之string字串

字串

#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;
}

结果:

STL容器之string字串

 

上一篇:经典笔试算法题之打小怪兽


下一篇:布尔盲注