CComBSTR, std::endl and stack overflow
I am not sure if this is a VC++/ATL related problem or with the way
std::endl works, so I have cross-posted this to 2 newsgroups. Please
trim appropriately if you feel this is OT for c.l.c++
I have a STL map that looks like this:
typedef std::map<ATL::CComBSTR, SomeStructure* ss> structMap;
structMap actualMap;
CComBSTR is just a wrapper over BSTR found in DCOM land. My question
is, I am iterating through this map and printing all the values to a
file like so:
ofstream ofs(...);
for (structMap::const_iterator itr = actualMap.begin(); itr !=
actualMap.end(); ++itr)
{
CComBSTR const& thekey = itr->first;
// use VC++ macro hocus-pocus to convert a BSTR to const char*
ofs << W2A(thekey.m_str);
ofs << std::endl;
}
If I comment out the first 2 lines inside the loop, everything works
fine (obviously I am priting the other members of SomeStructure).
Uncommenting them causes a stack overflow error deep in the bowels of
std::endl when it tries to flush the contents to the file. Is there
any known problems when W2A is called in a tight loop? My map can have
literally millions of entries.
I am sure I must be missing something obvious.. its been a long day and
I have been tearing my hair over this. any help will be greatly
appreciated.
thanks!