Thread: String class

  1. #1
    Registered User
    Join Date
    Jan 2009
    Posts
    197

    String class

    is there a property in String class in c++ which follows my requirement :

    print the string ( with just one character removed--- The character can be specified randomly)
    for eg:

    COMPUTER wiith 1 should give OMPUTER
    wait....
    No plz dont say that use in the for loop some other approach

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,412
    Ue the substr() member function. You would need to call it twice if the character to be ignored is in the middle of the string.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Jan 2009
    Posts
    197
    s...slice was another option i thought of.
    but... is the complexity better than O(n) ?????i mean to ask better than using for loop...
    I need an optimised one

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,412
    Quote Originally Posted by dpp
    s...slice was another option i thought of.
    I do not think that std::string has a slice member function. If you actually want to modify the string, you could just erase the character.

    Quote Originally Posted by dpp
    but... is the complexity better than O(n) ?????i mean to ask better than using for loop...
    No, the complexity cannot be better than O(n) in general, where n is the number of characters. It will not matter anyway, since printing must take O(n) time.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. String Class
    By BKurosawa in forum C++ Programming
    Replies: 117
    Last Post: 08-09-2007, 01:02 AM
  2. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  3. String issues
    By The_professor in forum C++ Programming
    Replies: 7
    Last Post: 06-12-2007, 09:11 AM
  4. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 05:45 PM
  5. class object manipulation
    By guda in forum C++ Programming
    Replies: 2
    Last Post: 10-09-2004, 10:43 AM