There are different ways to convert string to int in C and C++. Like using inbuilt function or custom code. Lets take a look on each of them one by one.

The programs below are written in C but the same concept will work for C++.

Ways to Convert String to int in C and C++

Using sscanf()

This function reads input directly from string. Take below example.



Using atoi()

It is another inbuilt function that can directly convert string to integer.

Using Manual Method

Here we will use our own custom logic for conversion.

No tags for this post.


Please enter your comment!
Please enter your name here