Ярослав Смирнов Asked:2020-01-12 00:26:08 +0000 UTC2020-01-12 00:26:08 +0000 UTC 2020-01-12 00:26:08 +0000 UTC C++ 中 Python 函数 str 和 int 的类似物 772 Python 中有两个函数:str和int。是否可以在 C++ 中像这样在字符串和数字之间切换?我有a = 10。这个数字可以转换为字符串(经过所有计算)吗? c++ 2 个回答 Voted Best Answer AnT stands with Russia 2020-01-12T01:19:54Z2020-01-12T01:19:54Z 该函数std::to_string将数字转换为字符串表示形式(in std::string)。该函数用于将数字转换为 C 字符串表示形式std::sprintf。 函数std::stoi(std::stol等std::stoll)以及函数std::from_chars将字符串转换为数字。 Sergey Gornostaev 2020-01-12T00:39:36Z2020-01-12T00:39:36Z int a = 10; char s[3]; itoa(a, s, 10);
该函数
std::to_string将数字转换为字符串表示形式(instd::string)。该函数用于将数字转换为 C 字符串表示形式std::sprintf。函数
std::stoi(std::stol等std::stoll)以及函数std::from_chars将字符串转换为数字。