25

I'm trying the elegant solution provided in this answer but no matter what I try, I cannot get passed the error Implicit instantiation of undefined template for this line:

std::ostringstream strs;

What I need to do? I've included the following, which I'm sure is overkill. As a second question it seems hard to track down what exactly needs to be included for ostringstream:

#include <iostream>
#include <fstream>
#include <iosfwd>
#include <ios>
Community
  • 1
  • 1
johnbakers
  • 24,158
  • 24
  • 130
  • 258
  • 1
    I see the link you have provided and if your intention is to change a double to string and you have C++11 support, just use `std::to_string(double)`. – stardust Apr 23 '13 at 10:34

1 Answers1

61

stringstream classes are defined in sstream header, so write

#include <sstream>

and all will be fine.

ForEveR
  • 55,233
  • 2
  • 119
  • 133
  • 1
    thanks, it worked, I'm curious how I could find this out easily myself. I looked it up and it doesn't say anything about this particular header: http://www.cplusplus.com/reference/sstream/ostringstream/. My compiler (Xcode) says it is declared in `iosfwd` – johnbakers Apr 23 '13 at 10:59
  • @SebbyJohanns `` only provides forward *declarations* for i/o classes. You need to `#include` the correct header in your cpp file for the *definition*. `` is present for use in headers where you do not need the full class definition. This helps in reducing compilation times. – indeterminately sequenced Apr 23 '13 at 11:11
  • 1
    thanks. i'd still like to know the best way to actually find out what headers include the full definitions of things like this. i was on quite a goose chase to track it down before posing here, and it seems like it should be an elementary task to look up. where would I do that? @indeterminatelysequenced – johnbakers Apr 23 '13 at 11:15
  • 1
    @SebbyJohanns [msdn](http://msdn.microsoft.com/en-us/library/vstudio/a7tkse1h.aspx) is the most reliable source I have found online. (other than the standard drafts). – indeterminately sequenced Apr 23 '13 at 11:20
  • 1
    @SebbyJohanns I think one clue is in the URL of the link you posted. Another is that on that page is highlighted in the top left menu. – john Apr 23 '13 at 11:38
  • 1
    @SebbyJohanns Use a [*better reference*](http://en.cppreference.com/w/cpp/io/basic_ostringstream). – Christian Rau Apr 23 '13 at 20:06
  • 1
    @indeterminatelysequenced *"msdn is the most reliable source I have found online"* - I wouldn't trust them so much regarding information about the C++ standard either (they made errors and inaccuracies before, though not neccessarily in this case). *cppreference.com* is still the most reliable source, even if still incomplete in certain parts. – Christian Rau Apr 23 '13 at 20:09