[英]OStringStream and Namespaces Issue C++
所以我想将整数转换成字符串,但是使用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
}
我在“ std :: ostringstream行:“未定义模板的隐式实例化”上收到错误。这是什么意思?我试图在顶部放置“ using namespace std;”,但没有效果。
您必须添加以下内容:
#include <sstream>
您需要包括标题<sstream>
。 您可能还应该包含<string>
,尽管对于返回字符串的ostringstream::str()
方法而言,这并不是严格必需的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.