keep an open stream

Discussion in 'C++' started by Gary Wessle, Feb 5, 2007.

  1. Gary Wessle

    Gary Wessle Guest

    Hi

    I need to save on open(ing) ifstream in a loop, so I thought to have a
    map<string, ifstream> where the input streams are open all them time.

    class A
    {
    std::map<std::string, std::ifstream> m_is;

    public:
    void populate_the _stream();
    };

    A::A()
    {
    for( vector<string>::iterator i = files_vec.begin(); i !=
    files_vec.end(); i++ )
    {
    m_is[*i] = ifstream (*i)( f.c_str() );

    hummmm

    not sure.

    thanks for helping
     
    Gary Wessle, Feb 5, 2007
    #1
    1. Advertising

  2. Gary Wessle

    Ian Collins Guest

    Gary Wessle wrote:
    > Hi
    >
    > I need to save on open(ing) ifstream in a loop, so I thought to have a
    > map<string, ifstream> where the input streams are open all them time.
    >
    > class A
    > {
    > std::map<std::string, std::ifstream> m_is;


    You can't copy an ifstream, so you can't store them in a container.

    --
    Ian Collins.
     
    Ian Collins, Feb 5, 2007
    #2
    1. Advertising

  3. Ian Collins schrieb:
    > Gary Wessle wrote:
    >> Hi
    >>
    >> I need to save on open(ing) ifstream in a loop, so I thought to have a
    >> map<string, ifstream> where the input streams are open all them time.
    >>
    >> class A
    >> {
    >> std::map<std::string, std::ifstream> m_is;

    >
    > You can't copy an ifstream, so you can't store them in a container.


    Right, but you can store a pointer or smart pointer in a container, like:

    std::map<std::string, boost::shared_ptr<std::ifstream> > m_is;

    --
    Thomas
    http://www.netmeister.org/news/learn2quote.html
     
    Thomas J. Gritzan, Feb 5, 2007
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Rasmusson, Lars
    Replies:
    1
    Views:
    783
    popov
    Apr 30, 2004
  2. Replies:
    9
    Views:
    676
    Alex Buell
    Apr 27, 2006
  3. Alexander Korsunsky

    get stream mode flags from an opened stream

    Alexander Korsunsky, Feb 17, 2007, in forum: C++
    Replies:
    1
    Views:
    478
    John Harrison
    Feb 17, 2007
  4. dolphin
    Replies:
    6
    Views:
    596
    Thomas Fritsch
    Mar 18, 2007
  5. hisan
    Replies:
    1
    Views:
    1,415
    Dan Stromberg
    Jun 25, 2012
Loading...

Share This Page