gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-04 15:20:42 25 4
gpt4 key购买 nike

将整数转换为以 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com