In this article, we will look at how we can convert a string to int in C++. Often, we may need to convert numeral strings into integers. We may need certain ways to quickly do the conversion
在本文中,我们将研究如何在C ++中将字符串转换为int。 通常,我们可能需要将数字字符串转换为整数。 我们可能需要某些方法来快速进行转换
Let’s take a look at various ways to convert a string to int.
让我们看一下将字符串转换为int的各种方法。
方法1 –使用std :: stoi (Method 1 – Using std::stoi)
To convert a std::string
object to an integer, this is the recommended option in C++. This takes in a string as input and returns an integer.
要将std::string
对象转换为整数,这是C ++中的推荐选项。 这将字符串作为输入并返回整数。
Here is a simple example:
这是一个简单的示例&#