Convert it into a C string and you're done
string s;
int i = atoi(s.c_str());
Answer from Matteo Pacini on Stack OverflowGeeksforGeeks
geeksforgeeks.org โบ c language โบ c-atoi-function
atoi() Function in C - GeeksforGeeks
October 13, 2025 - The atoi() function accepts a string (which represents an integer) as a parameter and yields an integer value in return. Defined inside <stdlib.h> header file. ... #include <stdio.h> #include <stdlib.h> int main() { char str[] = "12345"; int ...
12:23
LeetCode 8 | String To Integer ( atoi ) | Strings | C++ [ Algorithm ...
14:55
LeetCode: String To Integer (atoi) - YouTube
03:01
2 Easy Methods to Convert String to Integer in C++ - YouTube
05:52
Implement atoi | Convert string to integer - YouTube
06:22
String to Integer (atoi) LeetCode 8 | Easy & Clear Explanation ...
11:40
String to Integer atoi | Leetcode 8 | Implement atoi | Amazon ...
TutorialsPoint
tutorialspoint.com โบ c_standard_library โบ c_function_atoi.htm
C library - atoi() function
Following is the syntax of the c atoi() function โ ... This function returns an integral number, represents int value. If the input string is not a valid string's number, it returns 0.
TechOnTheNet
techonthenet.com โบ c_language โบ standard_library_functions โบ stdlib_h โบ atoi.php
C Language: atoi function (Convert String to Integer)
The atoi function returns the integer representation of a string. The atoi function skips all white-space characters at the beginning of the string, converts the subsequent characters as part of the number, and then stops when it encounters the first character that isn't a number.
GeeksforGeeks
geeksforgeeks.org โบ dsa โบ write-your-own-atoi
String to Integer - Write your own atoi() - GeeksforGeeks
... Traverse the string from left to right, skipping whitespaces, handling the optional sign, and building the number digit by digit. At each step, ensure the value stays within 32-bit integer limits to avoid overflow.
Published: April 14, 2026
ZetCode
zetcode.com โบ clang โบ atoi
C atoi Tutorial: String to Integer Conversion with Practical Examples
The atoi function converts a string to an integer. It's declared in stdlib.h and takes one parameter: the string to convert. atoi skips whitespace, then converts subsequent characters until it encounters a non-digit. It has no error detection - invalid input returns 0.
SysAdminSage
sysadminsage.com โบ home โบ blog โบ convert string to int c: full guide
Convert String to Int C: Full Guide - SysAdminSage
August 21, 2026 - If you require a quick, basic conversion and are not concerned with validating the input data, atoi() is straightforward. It takes a C-style string (const char*) and attempts to convert the beginning of the string into an integer (int).
WsCube Tech
wscubetech.com โบ resources โบ c-programming โบ programs โบ string-to-int
How to Convert String to Int in C? 5 Ways With Code
September 17, 2026 - Learn five easy ways to convert a string to an int in C using atoi(), strtol(), sscanf(), and manual conversion. Includes code examples!
TutorialsPoint
tutorialspoint.com โบ article โบ How-to-convert-a-string-to-a-integer-in-C
How to convert a string to a integer in C
#include <stdio.h> #include <stdlib.h> #include <string.h> int main() { char *name = "The Matrix(1999)"; char *ps; char year_str[5] = ""; int year, i; /* Find the opening bracket */ ps = strchr(name, '('); if (ps != NULL) { /* Extract characters between brackets */ for (i = 1; i < strlen(ps) - 1 && i < 5; i++) { year_str[i-1] = ps[i]; } year_str[4] = '\0'; /* Convert to integer */ year = atoi(year_str); printf("Movie: %s<br>", name); printf("Year: %d<br>", year); } return 0; }
Scaler
scaler.com โบ home โบ topics โบ atoi() function in c
atoi() function in C - Scaler Topics
October 14, 2022 - The atoi function in C takes a string (which represents an integer) as an argument & returns its value of type int. So basically the function is used to convert a string argument to an integer.
TutorialsPoint
tutorialspoint.com โบ article โบ c-program-to-write-your-own-atoi
C Program To Write Your Own atoi()
March 15, 2026 - String: "12345" -> Integer: 12345 String: " 678" -> Integer: 678 String: "99abc" -> Integer: 99 ยท This enhanced version handles both positive and negative numbers ยท #include <stdio.h> int myAtoi(const char *str) { int result = 0; int sign = 1; int i = 0; /* Skip leading whitespaces */ while (str[i] == ' ' || str[i] == '\t' || str[i] == '<br>') { i++; } /* Handle sign */ if (str[i] == '+' || str[i] == '-') { sign = (str[i] == '-') ?
Linux Man Pages
linux.die.net โบ man โบ 3 โบ atoi
atoi(3): convert string to integer - Linux man page
The atoi() function converts the initial portion of the string pointed to by nptr to int. The behavior is the same as strtol(nptr, NULL, 10); except that atoi() does not detect errors.
Northern Michigan University
nmu.edu โบ Webb โบ ArchivedHTML โบ MathComputerScience โบ c_programming โบ c_068.htm
C Programming - atoi()
atof() converts an ascii character array to a float atoi() converts an ascii character array to an integer itoa() converts an integer to a character array ยท Example ยท /* convert a string to an integer */ #include <stdio.h> #include <stdlib.h> char string[] = "1234"; main() { int sum; sum ...