String class

This is a discussion on String class within the C++ Programming forums, part of the General Programming Boards category; is there a property in String class in c++ which follows my requirement : print the string ( with just ...

  1. #1
    dpp
    dpp is offline
    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
    20,960
    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.
    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

  3. #3
    dpp
    dpp is offline
    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
    20,960
    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.
    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

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, 04:45 PM
  5. class object manipulation
    By guda in forum C++ Programming
    Replies: 2
    Last Post: 10-09-2004, 10:43 AM

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