adding strings to container

This is a discussion on adding strings to container within the C++ Programming forums, part of the General Programming Boards category; Is there a way with 1 line of code that reads strings from standard input and only adds the strings ...

  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
    21,588
    Perhaps by using copy_if with a predicate.
    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. 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, 02: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

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