itoa() 的 C++ 标准替代方法,用于将 int 转换为 base 10 char*

标签 c++ windows string int itoa

将整数转换为以 10 为底的字符*

std::itoa(ConCounter, ID, 10);

ConCounter是一个整数,ID是一个char*,以10为底

它说 iota 不是 std 的成员,如果没有 std,它就不会被声明。我知道这是一个非标准函数,但我包含了它的所有库,但它仍然看不到它。

有什么方法可以做到以上几点?任何快速的衬垫? 我试过以下方法;

std::to_string //it's not declared for me when using mingw, it doesn't exist.
snprintf/sprintf //should work but it gives me the "invalid conversion from 'int' to 'char *'"    error
std::stoi //has same problem as iota

最佳答案

试试这个:

#include <sstream>

int i = // your number
std::ostringstream digit;
digit<<i;
std::string numberString(digit.str());

关于itoa() 的 C++ 标准替代方法,用于将 int 转换为 base 10 char*,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20034537/

相关文章:

c++ - 如何安装libusb?

javascript - 如何按范围替换字符串?

c++ - 在 OpenGL 2.1 中,即使在 2d 空间(具有 2D 纹理)中使用 3D tex 坐标是否安全?

c++ - 获取光标所在窗口的窗口句柄

c++ - MFC:如何在一个函数中捕获每个对话框控件的焦点

c++ - 如何停止 wxProgressDialog 重新调整大小?

C++ friend 模板函数 - minGW 错误但不是 VS2015

c - windows操作系统中如何识别RAM地址空间?

c# - C# 中接受字符串的 TrimEnd 或 TrimStart 方法?

java - 相同的字符串不等于