文章目录
参考 stackoverflow: converting _int64 to a string,验证建议的代码可以成功地将_int64转换到string。
C++ 11的标准做法:
#include <string>
int main()
{
int64_t value = 100;
std::string asString = std::to_string(value);
return 0;
}
使用stringstream:
#include <string>
#include <sstream>
int main()
{
std::stringstream stream;
__int64 value(1000000000);
stream << value;
std::string strValue(stream.str());
return 0;
}
使用C sprintf() 或者 _i64toa()
__int64 value = ...;
char buffer[20];
sprintf(buffer, "%Ld", value);
__int64 value = ...;
char buffer[20];
_i64toa(value, buffer, 10);
参考
stackoverflow: converting _int64 to a string
Microsoft Docs: _itoa, _i64toa, _ui64toa, _itow, _i64tow, _ui64tow
本文介绍了几种在C++中将_int64类型的数据转换为string类型的有效方法,包括使用C++11标准库中的to_string函数、stringstream类以及传统的sprintf或_i64toa函数。

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



