ostringstream gives me Implicit instantiation error
14,031
stringstream
classes are defined in sstream
header, so write
#include <sstream>
and all will be fine.
Related videos on Youtube
Author by
johnbakers
likes programming computers, but never studied it anywhere. asks a few good questions and a lot of dumb ones (i've actually learned more from the stupid questions). looks up to nearly all other programmers, regardless of their age.
Updated on October 16, 2022Comments
-
johnbakers over 1 year
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>
-
stardust about 11 yearsI 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)
.
-
-
johnbakers about 11 yearsthanks, 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: cplusplus.com/reference/sstream/ostringstream. My compiler (Xcode) says it is declared in
iosfwd
-
indeterminately sequenced about 11 years@SebbyJohanns
<iosfwd>
only provides forward declarations for i/o classes. You need to#include
the correct header in your cpp file for the definition.<iosfwd>
is present for use in headers where you do not need the full class definition. This helps in reducing compilation times. -
johnbakers about 11 yearsthanks. 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
-
indeterminately sequenced about 11 years@SebbyJohanns msdn is the most reliable source I have found online. (other than the standard drafts).
-
john about 11 years@SebbyJohanns I think one clue is in the URL of the link you posted. Another is that on that page <sstream> is highlighted in the top left menu.
-
Christian Rau about 11 years@SebbyJohanns Use a better reference.
-
Christian Rau about 11 years@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.