在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
热门推荐
10 病人祝福语老师寄语简短
11 新娘生孩子祝福语简短
12 婆婆66岁祝福语简短
13 今天孩子高考祝福语简短
14 送彩票生日祝福语简短
15 分别祝福语简短情话英文
16 画室揭牌仪式祝福语简短
17 女友妈妈生日祝福语简短
18 离别赠言离职祝福语简短