substr and error checking

This is a discussion on substr and error checking within the C++ Programming forums, part of the General Programming Boards category; if we have a string for example "test" and call substr(0,3) for it it will give us the string tes ...

  1. #1
    nik
    nik is offline
    Registered User
    Join Date
    Nov 2010
    Posts
    44

    substr and error checking

    if we have a string for example "test"

    and call substr(0,3) for it it will give us the string tes right?

    but how does substr work when we call substr(0,10000);

    it will give us the string test, but will it check until it finds a '\0' or will it check all the 10000 bytes after the first character of the string? I mean, does substr check for such errors?

  2. #2
    a_capitalist_story
    Join Date
    Dec 2007
    Posts
    2,650
    substr doesn't take integer arguments. What are you talking about? substr(3): locate substring - Linux man page

  3. #3
    Registered User
    Join Date
    Oct 2006
    Posts
    2,360
    I think he's referring to std::string::substr(size_t, size_t).

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,630
    Well...
    Quote Originally Posted by C++03 Clause 21.3.6.7 basic_string::substr
    Code:
    basic_string<charT,traits,Allocator>
    substr(size_type pos = 0, size_type n = npos) const;
    Requires: pos <= size()
    Throws: out_of_range if pos > size().
    Effects: Determines the effective length rlen of the string to copy as the smaller of n and size() - pos.
    Returns: basic_string<charT,traits,Allocator>(data()+pos,rl en).
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    nik
    nik is offline
    Registered User
    Join Date
    Nov 2010
    Posts
    44
    ok I understand it now, thanks for help

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21