Thread: queue with string

  1. #1
    Registered User
    Join Date
    May 2009
    Location
    kuwait
    Posts
    9

    queue with string

    hellow ..

    how to wright a function that compresses a string by deleting all space characters in the string?

    hint" insert none space characters from the string into the queue.when you reach the end of the string ,dequeue the characters from the queue and place them back into the string"

    thanks

  2. #2
    The larch
    Join Date
    May 2006
    Posts
    3,573
    You'd need a queue<char>.

    Using the queue is no rocket science.
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

  3. #3
    Registered User
    Join Date
    May 2009
    Location
    kuwait
    Posts
    9
    well i just started my jurney in c++ thats why iam not that good in impleminting functions

  4. #4
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,817
    Is it a requirement of some exercise that you must use a queue? Can you just use the remove_if STL function and pass it a functor that equates to true for any space characters?
    "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

  5. #5
    Registered User
    Join Date
    May 2009
    Location
    kuwait
    Posts
    9
    yes it is a reqirement

  6. #6
    The larch
    Join Date
    May 2006
    Posts
    3,573
    hint" insert none space characters from the string into the queue.when you reach the end of the string ,dequeue the characters from the queue and place them back into the string"
    And what have you tried? This describes exactly how you should proceed.

    The functions you might need:
    std::queue<char>: push - puts in the queue, pop - removes from the queue, top - looks up the current item, empty - tests if something left to read from the queue.

    std::string: operator[] - for looking up a character, operator+= - for appending (a character), clear - for emptying the string.
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 8
    Last Post: 04-25-2008, 02:45 PM
  2. Message class ** Need help befor 12am tonight**
    By TransformedBG in forum C++ Programming
    Replies: 1
    Last Post: 11-29-2006, 11:03 PM
  3. Classes inheretance problem...
    By NANO in forum C++ Programming
    Replies: 12
    Last Post: 12-09-2002, 03:23 PM
  4. creating class, and linking files
    By JCK in forum C++ Programming
    Replies: 12
    Last Post: 12-08-2002, 02:45 PM
  5. Warnings, warnings, warnings?
    By spentdome in forum C Programming
    Replies: 25
    Last Post: 05-27-2002, 06:49 PM