zoukankan      html  css  js  c++  java
  • string::substr()简介

    std::basic_string::substr

    C++
    Strings library
    std::basic_string

    basic_string substr( size_type pos = 0, size_type count = npos );

    Returns a substring [pos, pos+count). If the requested substring lasts past the end of the string, or if count == npos, the returned substring is [pos, size()).

    Parameters

    pos   position of the first character to include

    count  length of the substring

    Return value

    String containing the substring [pos, pos+count).

    Exceptions

    std::out_of_range if pos > size().

    Complexity

    Linear in count

    Example

     1 #include <string>
     2 #include <iostream>
     3  
     4 int main()
     5 {
     6     std::string a = "0123456789abcdefghij";
     7  
     8     std::string sub1 = a.substr(10);
     9     std::cout << sub1 << '\n';
    10  
    11     std::string sub2 = a.substr(5, 3);
    12     std::cout << sub2 << '\n';
    13  
    14     std::string sub3 = a.substr(12, 100);
    15     std::cout << sub3 << '\n';
    16  }

    Output:

    1 abcdefghij
    2 567
    3 cdefghij
    **************************************************************
    我喜欢程序员,他们单纯、固执、容易体会到成就感;面对困难,能够不休不眠;面对压力,能够迎接挑战。他们也会感到困惑与傍徨,但每个程序员的心中都有一个比尔盖茨或是乔布斯的梦想,用智慧把属于自己的事业开创。其实我是一个程序员
    [=.=]
  • 相关阅读:
    hdu 3342 Legal or Not 拓排序
    hdu 1596 find the safest road Dijkstra
    hdu 1874 畅通工程续 Dijkstra
    poj 2676 sudoku dfs
    poj 2251 BFS
    poj Prime Path BFS
    poj 3278 BFS
    poj 2387 Dijkstra 模板
    poj 3083 DFS 和BFS
    poj 1062 昂贵的聘礼 dijkstra
  • 原文地址:https://www.cnblogs.com/kevinGaoblog/p/2601328.html
Copyright © 2011-2022 走看看