我正在尝试让我的每秒帧数读数出现在我的窗口标题中。我以前做过一次,但是我该如何设置代码来做呢?我需要从float切换到const char *。
发布于 2012-05-21 05:58:09
一种简单的方法是,让它与每一个数字都兼容:
#include <sstream>
template<class T>
char* toChar(T t) {
std::ostringstream oss;
oss << t;
return oss.str().c_str();
}这样,无论您使用int、float、long还是其他任何类型,它都会工作,并将其作为char*字符串返回。
发布于 2012-05-21 03:12:59
您可以使用istringstream,然后使用str(),然后使用c_str()。
https://stackoverflow.com/questions/10676364
复制相似问题