keep an open stream

G

Gary Wessle

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
 
I

Ian Collins

Gary said:
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.
 
T

Thomas J. Gritzan

Ian said:
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;
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,040
Latest member
papereejit

Latest Threads

Top