How can I post-initialize an stringstream inside a map?
Is it even possible or do I have to create a stringstream*?
std::map<std::string, std::stringstream> mapTopics;
if(mapTopics.end() == mapTopics.find(Topic))
{
mapTopics[Topic] = std::stringstream(""); // Post Initialize <---
}
std::map<std::string, std::stringstream>::iterator mapTopicsIter = mapTopics.find(Topic);
mapTopicsIter->second << " <say speaker=\"" << sSpeaker << "\">" << label << "</say>" << std::endl;
You cannot. STL containers require their data elements to be copyable, and streams are not copyable.
Why do you want to have streams in a map? Can’t you store the strings?
If you are really desperate, you will have to store pointers to (most likely dynamically allocated) string streams:
This has the advantage that, would you store pointers to a stream base class, you could later also add other streams to the map.