在地图内初始化字符串流?
如何在地图内后初始化字符串流?
是否有可能或者我必须创建一个 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;
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;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你不能。 STL容器要求其数据元素可复制,而流则不可复制。
为什么要在地图中包含流?你不能存储字符串吗?
如果你真的很绝望,你将不得不存储指向(很可能是动态分配的)字符串流的指针:
这样做的优点是,如果你存储指向流基类的指针,你以后还可以将其他流添加到映射中。
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.
不确定这是否是你的意思,但是怎么样:
Not sure If its what you mean but how about :