【问题标题】:ostringstream gives me Implicit instantiation errorostringstream 给了我隐式实例化错误
【发布时间】:2013-04-23 10:30:45
【问题描述】:

我正在尝试this answer 中提供的优雅解决方案,但无论我尝试什么,我都无法通过此行的错误Implicit instantiation of undefined template

std::ostringstream strs;

我需要做什么?我已经包括了以下内容,我敢肯定这是矫枉过正的。作为第二个问题,似乎很难找到 ostringstream 究竟需要包含哪些内容:

#include <iostream>
#include <fstream>
#include <iosfwd>
#include <ios>

【问题讨论】:

  • 我看到了您提供的链接,如果您打算将 double 更改为字符串并且您支持 C++11,请使用 std::to_string(double)

标签: c++ string


【解决方案1】:

stringstream 类在sstream 头中定义,所以写

#include <sstream>

一切都会好起来的。

【讨论】:

  • 谢谢,它成功了,我很好奇我自己是如何轻松找到这个的。我查了一下,它没有说明这个特定的标题:cplusplus.com/reference/sstream/ostringstream。我的编译器(Xcode)说它是在iosfwd 中声明的
  • 谢谢。我仍然想知道实际找出哪些标题包含此类事物的完整定义的最佳方法。在这里摆姿势之前,我一直在追寻它,看起来这应该是一项基本任务。我会在哪里做呢? @indeterminatelysequenced
  • @SebbyJohanns msdn 是我在网上找到的最可靠的来源。 (标准草案除外)。
  • @SebbyJohanns 我认为一条线索在您发布的链接的 URL 中。另一个是该页面上的 在左上角菜单中突出显示。
  • @SebbyJohanns 使用better reference
猜你喜欢
  • 2019-11-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-09-02
相关资源
最近更新 更多