string转换为int类C++
时间: 2023-06-04 13:04:10 浏览: 78
抱歉,我可以回答这个问题。在C语言中,可以使用atoi函数将字符串转换为整型数。例如:
```
#include <stdlib.h>
int main() {
char str[] = "123";
int num = atoi(str);
printf("str转换成的整型数为:%d\n", num);
return 0;
}
```
相关问题
c++将string类转化为int类
可以使用`stoi`函数将`string`类型转化为`int`类型,示例如下:
```
#include <iostream>
#include <string>
using namespace std;
int main() {
string str = "1234";
int num = stoi(str);
cout << "num = " << num << endl;
return 0;
}
```
输出结果为:
```
num = 1234
```
C++将string类转化为int类
可以使用`stoi`函数将`string`类型转化为`int`类型,示例如下:
```
#include <iostream>
#include <string>
using namespace std;
int main() {
string str = "1234";
int num = stoi(str);
cout << "num = " << num << endl;
return 0;
}
```
输出结果为:
```
num = 1234
```
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)