Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
C++
C++ Primer ex 9.27
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="arnuld, post: 3091935"] /* C++ Primer - 4/e * * Exercise: 9.27 * STATEMENT * Write a program to process a list of strings. Look for a particular value and if found remove it. Repeat the program usinig a * deque. * * */ #include <iostream> #include <list> #include <deque> #include <algorithm> #include <iterator> int main() { std::cout << "Enter some words: "; std::list<std::string> slist; std::copy( std::istream_iterator<std::string>( std::cin ), std::istream_iterator<std::string>(), std::back_inserter( slist ) ); std::cin.clear(); std::cout << "Enter the word you want to remove: "; std::string rem_word; std::cin >> rem_word; std::remove( slist.begin(), slist.end(), rem_word); std::copy( slist.begin(), slist.end(), std::ostream_iterator<std::string>( std::cout, " " ) ); std::cout << std::endl; return 0; } ============= OUTPUT ============= /home/arnuld/programming/c++ $ g++ -ansi -pedantic -Wall -Wextra ex_09.27.cpp /home/arnuld/programming/c++ $ ./a.out Enter some words: ab cd ef gh Enter the word you want to remove: ef ab cd gh gh /home/arnuld/programming/c++ $ Did you notice ? The "ef" was NOT removed but replcaed with "gh" . Why so ? It is std::remove algorithm and should remove, not replace. -- arnuld [URL]http://lispmachine.wordpress.com[/URL] [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
C++
C++ Primer ex 9.27
Top