copy string not from beginning

This is a discussion on copy string not from beginning within the C++ Programming forums, part of the General Programming Boards category; I want to copy a string without the first four characters. It doesn't matter weather or not it's c or ...

  1. #1
    Registered User
    Join Date
    Sep 2007
    Posts
    18

    copy string not from beginning

    I want to copy a string without the first four characters. It doesn't matter weather or not it's c or c++ style strings.

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    13,007
    Start copying at foo[4].

  3. #3
    Registered User
    Join Date
    Apr 2006
    Posts
    1,875
    Code:
    //For std::string
    std::copy(str.begin()+4,str.end(),copytoItr);
    //for c-string
    std::copy(str+4,str+STR_LEN,copytoItr);
    It is too clear and so it is hard to see.
    A dunce once searched for fire with a lighted lantern.
    Had he known what fire was,
    He could have cooked his rice much sooner.

  4. #4
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,681
    Code:
    std::string oldstring("Hey there!");
    std::string newstring(oldstring.substr(4));  // newstring = "there!"
    I used to be an adventurer like you... then I took an arrow to the knee.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 1
    Last Post: 12-10-2008, 10:29 AM
  2. OOP Question DB Access Wrapper Classes
    By digioz in forum C# Programming
    Replies: 2
    Last Post: 09-07-2008, 04:30 PM
  3. String Class
    By BKurosawa in forum C++ Programming
    Replies: 117
    Last Post: 08-09-2007, 01:02 AM
  4. Message class ** Need help befor 12am tonight**
    By TransformedBG in forum C++ Programming
    Replies: 1
    Last Post: 11-29-2006, 10:03 PM
  5. Replies: 3
    Last Post: 11-03-2002, 01:14 AM

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