Thread: copy string not from beginning

  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
    14,336
    Start copying at foo[4].

  3. #3
    Registered User
    Join Date
    Apr 2006
    Posts
    2,149
    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,817
    Code:
    std::string oldstring("Hey there!");
    std::string newstring(oldstring.substr(4));  // newstring = "there!"
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 1
    Last Post: 12-10-2008, 11: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, 11:03 PM
  5. Replies: 3
    Last Post: 11-03-2002, 02:14 AM