Thread: adding strings to container

  1. #1
    Registered User
    Join Date
    Jan 2007
    Posts
    330

    adding strings to container

    Is there a way with 1 line of code that reads strings from standard input and only adds the strings that are less than 5 characters long?

    something like this but then with a predicate?

    Code:
    copy(istream_iterator<std::string>(std::cin), 
            istream_iterator<std::string>(), 
            back_inserter(v)); // add only certain ones?

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Perhaps by using copy_if with a predicate.
    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. Storing Many Strings- Which STL Container?
    By bengreenwood in forum C++ Programming
    Replies: 7
    Last Post: 08-27-2009, 05:13 AM
  2. adding strings?
    By Led4urhead123 in forum C++ Programming
    Replies: 2
    Last Post: 07-10-2008, 03:13 PM
  3. Replies: 4
    Last Post: 03-21-2004, 03:34 PM
  4. adding onto strings
    By Granger9 in forum C Programming
    Replies: 6
    Last Post: 09-11-2002, 01:06 PM
  5. Adding to strings..
    By SyntaxBubble in forum Windows Programming
    Replies: 1
    Last Post: 10-25-2001, 04:22 PM