OStringStream和Namespaces问题C++

pri*_*nce 1 c++ namespaces ostringstream

所以我想将一个整数转换成一个字符串但是使用itoa不是标准的,所以通过我的研究我认为最好的方法是使用OStringStream.这是一些伪代码:

#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
}
Run Code Online (Sandbox Code Playgroud)

我在"std :: ostringstream"上遇到错误:"未定义模板的隐式实例化".这是什么意思?我尝试在顶部放置"using namespace std;"但它没有任何效果.

小智 9

您必须添加以下内容:

#include <sstream>
Run Code Online (Sandbox Code Playgroud)


jua*_*nza 5

你需要包含标题<sstream>.您可能还应该包括<string>,尽管在给定字符串返回ostringstream::str()方法的情况下并不是必需的.