Norway


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 directly from string. Take below example.

Output

12345

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.

LEAVE A REPLY

Please enter your comment!
Please enter your name here