所以我想把一个整数转换成一个字符串,但是使用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 line:"Implicit instantiation of undefined template“上得到了一个错误。这是什么意思?我试着把"using namespace std;”放在最上面,但是没有效果。
发布于 2012-08-27 22:54:07
您必须添加以下内容:
#include <sstream>发布于 2012-08-27 22:55:07
您需要包含标头<sstream>。您可能还应该包含<string>,尽管对于返回字符串的ostringstream::str()方法,这并不是必须的。
https://stackoverflow.com/questions/12144407
复制相似问题