- The C Standard Library
Stoi is a C11 function. If you aren't using a compiler that understands C11, this simply won't compile. If you aren't using a compiler that understands C11, this simply won't compile. You can use a stringstream instead to read the input. Parses str interpreting its content as an integral number of the specified base, which is returned as an int value. If idx is not a null pointer, the function also sets the value of idx to the position of the first character in str after the number. The function uses strtol (or wcstol) to perform the conversion (see strtol for more details on the process). Output: 5 5 5 If conversion is not performed, an invalidargument exception is thrown. If the value read is out of the range of representable values by a double an outofrange exception is thrown.
- C Standard Library Resources
- C Programming Resources
- Selected Reading
Description
The C library function int atoi(const char *str) converts the string argument str to an integer (type int).
Declaration
Following is the declaration for atoi() function.
Parameters
- str − This is the string representation of an integral number.
![Dev c++ online Dev c++ online](https://www.liuchuo.net/wp-content/uploads/2018/09/4D9497FC-EF96-4941-8330-9AD0EA3F98A4.png)
Return Value
This function returns the converted integral number as an int value. If no valid conversion could be performed, it returns zero.
Example
The following example shows the usage of atoi() function.
Dev C++ Online
Let us compile and run the above program that will produce the following result −
Dev C++ For Windows 10
stdlib_h.htm