方法一:
char* PlayLayer::myToString(int count)
{
char* countBuf = new char[25];
sprintf(countBuf, "%d", count);
//point = objectes->getObject(countBuf);
return countBuf;
}
将to_string()替换为std:to_string()
方法二:
首先写一个 stdtostring.h 文件:
#ifndef STDTOSTRING_H
#define STDTOSTRING_H
#include <string>
#include <sstream>
using namespace std;
namespace std
{
template < typename T > std::string to_string( const T& n )
{
std::ostringstream stm ;
stm << n ;
return stm.str() ;
}
}
#endif然后在需要使用 std::to_stirng() 方法的源文件中包含它:
#if CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID #include "stdtostring.h" #endif参考:https://blog.youkuaiyun.com/Anzhongliu/article/details/51465507

本文介绍了两种在C++中将整数转换为字符串的方法:一种是使用标准C库函数sprintf结合new分配内存;另一种则是通过定义模板函数利用std::ostringstream实现更泛型化的转换。后者还提供了如何在特定平台(如Android)上引入该方法的具体步骤。
1998

被折叠的 条评论
为什么被折叠?



