views:

40

answers:

1

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;
+2  A: 

How can I post-initialize an stringstream inside a map?

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:

std::map<std::string, std::shared_ptr<std::stringstream> > stream_map;

This has the advantage that, would you store pointers to a stream base class, you could later also add other streams to the map.

sbi
Right, forgot about that.
Klaim
thanks as i thaugt ;(
Hendrik