gpt4 book ai didi

c++ - 如何将 C++ 字符串转换为 int?

转载 作者:IT老高 更新时间:2023-10-28 13:58:46 26 4
gpt4 key购买 nike

Possible Duplicate:
How to parse a string to an int in C++?

如何将 C++ 字符串转换为 int?

假设您希望字符串中包含实际数字(例如,“1”、“345”、“38944”)。

另外,假设你没有 boost,你真的想用 C++ 的方式,而不是笨拙的旧 C 方式。

最佳答案

#include <sstream>

// st is input string
int result;
stringstream(st) >> result;

关于c++ - 如何将 C++ 字符串转换为 int?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/200090/

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