keep an open stream

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Gary Wessle

    keep an open stream

    Hi

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

    class A
    {
    std::map<std::s tring, std::ifstreamm_ 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

  • Ian Collins

    #2
    Re: keep an open stream

    Gary Wessle wrote:
    Hi
    >
    I need to save on open(ing) ifstream in a loop, so I thought to have a
    map<string, ifstreamwhere the input streams are open all them time.
    >
    class A
    {
    std::map<std::s tring, std::ifstreamm_ is;
    You can't copy an ifstream, so you can't store them in a container.

    --
    Ian Collins.

    Comment

    • Thomas J. Gritzan

      #3
      Re: keep an open stream

      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, ifstreamwhere the input streams are open all them time.
      >>
      >class A
      >{
      > std::map<std::s tring, std::ifstreamm_ 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::s tring, boost::shared_p tr<std::ifstrea m m_is;

      --
      Thomas

      Comment

      Working...