utilizing a map with ofstreams, and a map with mutexes
I have a map of <char, ofstream*> & a map of <char,
mutex*>. I can compile this program, I am getting errors at
runtime. I am able to set up the maps, but I am unable to access the
ofstreams or mutexes I need.
I have stored these in a map because I require access to 26
files, but I cannot open and close them each time I need access,
because of efficiency, I also realize that this could be done more
easily from an array, but i'm concerned with how to use the map
container specifically.
I am using Microsoft Visual Studio.NET to compile this code.
Here is some of the relevant code, This is a multi-threaded program
and I also have a map<char, boost::mutex*>, which I am having
the same issues with. Any advice?
assume all the relevant #includes and using namespaces are added, the
maps have been created and the ofstreams and mutexes inserted,
typedef map<char, ofstream*> map_type;
typedef map<char, mutex*> mutex_type;
void cpApp::write_to_file(string w){
char first = *w.begin();
map_type::iterator i = stream_map.find(first);
mutex_type::iterator j = mutex_map.find(first);
mutex::scoped_lock lock (( *j->second ) );
//won't work
(*i->second) << w << endl;
//won't work
}
//basically I need to be able to access the mutex referenced in the
mutex_map, lock it, then use the referenced ofstream in the
stream_map to write the string to a file. Please let me know if I
need to provide any more information, and Thanks in advance for any
help^^
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]