在 C++ 中将数字字符串转换为整数
在此,我们将了解如何将数字字符串转换为整数类型数据。我们可以使用 atoi() 函数来解决此问题。此函数将字符串作为输入并转换为整数数据。
atoi() 函数存在于 <<cstdlib> 库中。
Input: A number string “1234” Output: 1234
算法
Step 1: Take a number string Step 2: Convert it to integer using atoi() function Step 3: Print the result. Step 4: End
示例代码
#include<iostream>
#include<cstdlib>
using namespace std;
main() {
int n;
char num_string[20] = "1234";
n = atoi(num_string);
cout << n;
}输出
1234
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP