I'm using maps and writing files for the first time and I get a crazy compiler error when I try to compile the following code. I'm sure it's something stupid, but I've been staring at this thing for too long, so any help would be appreciated.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
//map is named schedules
// saveSchedule() is a member of the Schedule class that writes a vector of
//objects to disk, or is supposed to
ofstream newFile("sched.txt");
map<string,Schedule>::iterator in;
for(in=schedules.begin(); in!=schedules.end();in++)
{
Schedule saveSched;
saveSched = in->second;
newFile<< (in->first)<<" : " << saveSched.saveSchedule()
<< endl;
}
newFile.close();
date_driver.cpp:218:20: error: no matching function for call to ‘std::basic_ofstream<char>::write(std::pair<const std::basic_string<char>, Schedule>&)’
but the above error came after I tried to change it use write(). Still no good. Here's what it looks like now
write() takes two parameters, a character array and an integral value. Looks like your code is trying to send in an iterator to the map. There's no overload of the write() function for that.