gpt4 book ai didi

c++ - 十进制字符串转char

转载 作者:太空狗 更新时间:2023-10-29 23:41:48 24 4
gpt4 key购买 nike

有没有办法将数字字符串转换为包含该值的 char?例如,字符串“128”应转换为包含值 128char

最佳答案

是的...来自 C 的 atoi

char mychar = (char)atoi("128");

更面向 C++ 的方法是...

template<class T>
T fromString(const std::string& s)
{
std::istringstream stream (s);
T t;
stream >> t;
return t;
}

char mychar = (char)fromString<int>(mycppstring);

关于c++ - 十进制字符串转char,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7920774/

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