Convert it into a C string and you're done
string s;
int i = atoi(s.c_str());
Answer from Matteo Pacini on Stack Overflowcppreference.com
en.cppreference.com › cpp › string › byte › atoi
std::atoi, std::atol, std::atoll - cppreference.com
Interprets an integer value in a byte string pointed to by str.
09:36
LeetCode String to Integer (atoi) | Java - YouTube
16:59
String to Integer atoi 🔥| Leetcode 8 | String - YouTube
07:47
String To Integer (atoi) - 8. LeetCode - Java - YouTube
07:35
Implement Atoi || String 5|| Placement Preparation Series || ...
15:04
STRING TO INTEGER (ATOI) | PYTHON | LEETCODE # 8 - YouTube
TutorialsPoint
tutorialspoint.com › c_standard_library › c_function_atoi.htm
C library - atoi() function
#include <stdlib.h> #include <stdio.h> int main(void) { int val; char *str; str = "1509.10E"; val = atoi(str); printf("integral number = %d", val); } ... The below c example concatenate two string and then convert the resulting string into a integral number using the atoi().
Cplusplus
cplusplus.com › reference › cstdlib › atoi
Atoi - Convert string to integer
int atoi (const char * str); Convert string to integer · Parses the C-string str interpreting its content as an integral number, which is returned as a value of type int. The function first discards as many whitespace characters (as in isspace) as necessary until the first non-whitespace character ...
GeeksforGeeks
geeksforgeeks.org › dsa › write-your-own-atoi
String to Integer - Write your own atoi() - GeeksforGeeks
Write your own atoi() that takes a string (which represents a floating point value) as an argument and returns its value as double.
Published: April 14, 2026
W3Schools
w3schools.com › c › ref_stdlib_atoi.php
C stdlib atoi() Function
The atoi() function reads a representation of a whole number from a string and returns its value.
cppreference.com
en.cppreference.com › c › string › byte › atoi
atoi, atol, atoll - cppreference.com
Interprets an integer value in a byte string pointed to by str.
Address: 5851 Legacy Circle, 6th Floor, Plano, TX 75024 United States
SAS
support.sas.com › documentation › onlinedoc › sasc › doc700 › html › lr1 › z2054672.htm
Function Descriptions : atoi
atoi converts the character string str to an integer. The string should consist of an optional plus or minus sign, followed by one or more decimal digits.
Reddit
reddit.com › r/learnprogramming › how do you use 'atoi'? (c)
r/learnprogramming on Reddit: How do you use 'atoi'? (C)
June 4, 2022 -
I want to assign an integer variable as a string. So if char *s = "123";, and int x;, I want to assign x to be whatever s is, so in this case "123". I asked a few hours ago and a lot of people said to use atoi. I tried researching it and from what I gathered it's a function that's in the header file stdlib.h, but no one really explained how to use it or what it does specifically. Also in every website I went to, they all said to use the syntax int atoi(const char *string), but if the function has already been declared in the header file, I don't see why there is a need to put a prototype. Can anyone explain this in a little more detail?
Thank you.
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.
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.
Authors: Peter PrinzTony Crawford
Published: 2005
Pages: 618
Stack Overflow
stackoverflow.com › questions › 16346332 › cant-make-atoi-take-in-a-string-string-vs-c-string
c++ - Can't make atoi take in a string (string vs. C-string?) - Stack Overflow
May 22, 2017 - I have read a line from a file and I am trying to convert it to an int. For some reason atoi() (convert string to integer) won't accept a std::string as an argument (possibly some issue with string...
AlgoMonster
algo.monster › home › 8. string to integer (atoi)
8. String to Integer (atoi) - In-Depth Explanation
The problem asks you to implement a function myAtoi(string s) that converts a string to a 32-bit signed integer, similar to C/C++'s atoi function.
Cppreference
cppreference.net › c › string › byte › atoi.html
atoi, atol, atoll - cppreference.net
Interprets an integer value in a byte string pointed to by str.
CS50
manual.cs50.io › 3 › atoi
atoi - CS50 Manual Pages
The atoi() function converts the initial portion of the string pointed to by nptr to int.