G
Gary Wessle
Hi
I am getting a seg fault, only if I replace the "(*m_os[*i])" with
"cout" it prints. how can I fix this?
the example below given as a representation of the part of a larger
code which exebits the problem.
many thanks
class A
{
std::map<std::string, std:fstream*> m_os;
std::map<std::string, myType> t4s;
std::vector<string> file_names;
public:
A(){}
void A_Mthd();
};
A::A()
{
void populate();
}
void A:opulate()
{
/* some code to fill file_names vector here */
/* Populate the ostream pointers map. */
for( vector<string>::iterator i = file_names.begin(); i != file_names.end(); i++ )
{
string f = "mydirectory/" + (*i);
ofstream* p_of = new ofstream( f.c_str(), ios::app);
m_os[*i] = p_of;
}
void A::A_Mthd(){
for( vector<string>::iterator i = file_names.begin(); i != file_names.end(); i++ )
(*m_os[*i]) << t4s[*i].B_Mthd() << " " << endl;
}
I am getting a seg fault, only if I replace the "(*m_os[*i])" with
"cout" it prints. how can I fix this?
the example below given as a representation of the part of a larger
code which exebits the problem.
many thanks
class A
{
std::map<std::string, std:fstream*> m_os;
std::map<std::string, myType> t4s;
std::vector<string> file_names;
public:
A(){}
void A_Mthd();
};
A::A()
{
void populate();
}
void A:opulate()
{
/* some code to fill file_names vector here */
/* Populate the ostream pointers map. */
for( vector<string>::iterator i = file_names.begin(); i != file_names.end(); i++ )
{
string f = "mydirectory/" + (*i);
ofstream* p_of = new ofstream( f.c_str(), ios::app);
m_os[*i] = p_of;
}
void A::A_Mthd(){
for( vector<string>::iterator i = file_names.begin(); i != file_names.end(); i++ )
(*m_os[*i]) << t4s[*i].B_Mthd() << " " << endl;
}