c ++atoi函数_atoi()函数以及C ++中的示例
c ++atoi函數
C ++ atoi()函數 (C++ atoi() function)
atoi() function is a library function of cstdlib header. It is used to convert the given string value to the integer value. It accepts a string containing an integer (integral) number and returns its integer value.
atoi()函數是cstdlib標頭的庫函數。 它用于將給定的字符串值轉換為整數值。 它接受包含整數(整數)的字符串,并返回其整數值。
Syntax of atoi() function:
atoi()函數的語法:
C++11:
C ++ 11:
int atoi (const char * str);Parameter(s):
參數:
str – represents a string containing an integer (integral) number.
str –表示包含整數(整數)的字符串。
Return value:
返回值:
The return type of this function is int, it returns the integer converted value.
該函數的返回類型為int ,它返回整數轉換后的值。
Example:
例:
Input:str = "123";Function call:atoi(str);Output:123C ++代碼演示atoi()函數的示例 (C++ code to demonstrate the example of atoi() function)
// C++ code to demonstrate the example of // atoi() function#include <iostream> #include <cstdlib> #include <string.h> using namespace std;// main() section int main() {char str[50];strcpy(str, "123");cout << "atoi(\"" << str << "\"): " << atoi(str) << endl;strcpy(str, "-123");cout << "atoi(\"" << str << "\"): " << atoi(str) << endl;strcpy(str, "0");cout << "atoi(\"" << str << "\"): " << atoi(str) << endl;strcpy(str, "1234567");cout << "atoi(\"" << str << "\"): " << atoi(str) << endl;strcpy(str, "12345678");cout << "atoi(\"" << str << "\"): " << atoi(str) << endl;strcpy(str, "-12345678");cout << "atoi(\"" << str << "\"): " << atoi(str) << endl;return 0; }Output
輸出量
atoi("123"): 123 atoi("-123"): -123 atoi("0"): 0 atoi("1234567"): 1234567 atoi("12345678"): 12345678 atoi("-12345678"): -12345678Reference: C++ atoi() function
參考: C ++ atoi()函數
翻譯自: https://www.includehelp.com/cpp-tutorial/atoi-function-with-example.aspx
c ++atoi函數
總結
以上是生活随笔為你收集整理的c ++atoi函数_atoi()函数以及C ++中的示例的全部內容,希望文章能夠幫你解決所遇到的問題。
                            
                        - 上一篇: 计算机操作系统 内存_计算机内存的类型|
 - 下一篇: 什么是苹果耳塞?