在 C 中不使用 itoa() 将整数转换为字符串
问题:
寻求一个C 中整数到字符串转换的 itoa() 替代方案,因为它会生成警告
答案:
幸运的是,C 提供了多种解决方案:
C 11 和Beyond:
std::to_string: 该函数直接将整数转换为字符串:
#include <string> int i = 5; std::string s = std::to_string(i);</string>
预C 11:
C Streams: 利用以下流操作:
#include <sstream> int i = 5; std::stringstream out; out </sstream>
有问题的示例改编自http://notfaq.wordpress.com/2006/08/30/c-convert-int-to-string/。
以上是如何在 C 中不使用 itoa() 将整数转换为字符串?的详细内容。更多信息请关注PHP中文网其他相关文章!