1

so I wanted to convert an integer into a string but using itoa isn't standard so through my research I figured the best way to do it would be to use OStringStream. Here's some pseudo-code:

#include <iostream>
#include <cmath>
#include <cstdlib>


std::string plusMinus(int x) {

    std::ostringstream x_str;
    // more code here obviously

}

int main(int argc, const char * argv[])
{
    // some cin/cout functions here
}

I get an error on the "std::ostringstream line: "Implicit instantiation of undefined template". What does this mean? I've tried putting "using namespace std;" at the top but it has no effect.

prince
  • 506
  • 6
  • 18
  • 4
    To convert an `int` to `std::string` see http://stackoverflow.com/questions/10516196/append-an-int-to-a-stdstring/10516313#10516313 for some solutions. – hmjd Aug 27 '12 at 14:55
  • 1
    In modern C++, say `std::to_string(x)`, from the `` header. – Kerrek SB Aug 27 '12 at 14:56

2 Answers2

9

You have to add the following include:

#include <sstream>
Andrés Senac
  • 841
  • 6
  • 14
5

You need to include header <sstream>. You should probably also include <string>, although that isn't strictly necessary given the string-returning ostringstream::str() method.

juanchopanza
  • 223,364
  • 34
  • 402
  • 480