Topic: Current use of istream_iterator...


Author: mangino@saturn.planet.net (Reed Mangino)
Date: 1997/09/11
Raw View
Based upon the current "standard" couldn't a vector<> be
initialized using two istream_iterator objects?

For example:

int main()
{
   ifstream is("test.txt");
   istream_iterator<string> ii(is);
   istream_iterator<string> eos; // used like EOF

   vector<string> strvec(ii, eos); // should read in file

   return 0;
}

Many STL implementations that I have seen have a vector constructor
that takes two const_iterators, others use a template member.
Could someone please explain why the above code is "non-standard"?

Thank you,
Reed

--

    ^^-__-^^-__-^^-__-^^-__-^^-__-^^-__-^^-__-^^-__-^^^-__-^^
     Reed R. Mangino       |  ** Dialogic Corporation **
     manginor@dialogic.com | World leader in the design of
     mangino@planet.net    |  computer telephony systems
   -----------------------------------------------------------
---
[ comp.std.c++ is moderated.  To submit articles: Try just posting with your
                newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  Comments? mailto:std-c++-request@ncar.ucar.edu
]





Author: steagall@deltalogic.com (Bob Steagall)
Date: 1997/09/11
Raw View
mangino@saturn.planet.net (Reed Mangino) wrote:

>Based upon the current "standard" couldn't a vector<> be
>initialized using two istream_iterator objects?

Yes, assuming your compiler supports template member functions.

[... code snipped ...]

>Could someone please explain why the above code is "non-standard"?

It is standard.  However, it won't work unless your compiler supports
template member functions and your standard library implementation is
aware of this support.

--Bob

====================================================================
Bob Steagall                                 steagall@deltalogic.com
DeltaLogic, Inc.                           http://www.deltalogic.com
1537 Kew Road                                   Voice (216) 321-8200
Cleveland Hts, OH 44118-1204                    Fax   (216) 321-6976
---
[ comp.std.c++ is moderated.  To submit articles: Try just posting with your
                newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  Comments? mailto:std-c++-request@ncar.ucar.edu
]