在 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