|Lessons||Lesson 28: String Conversion Functions|
When we get input of a different type other than the type of variable in which the value is being stored, it warrants the need to convert that type into another type.
These conversion functions take an argument of a type and return it after converting into another type. These functions and their description are given in the table below.
Use of String Conversion functions:
While writing main () in a program, we can put them inside the parentheses of main. ‘int arg c, char ** arg v are written inside the parentheses. The arg c is the count of number of arguments passed to the program including the name of the program itself while arg v is a vector of strings or an array of strings. It is used while giving command line arguments to the program.
The arguments in the command line will always be character strings. The number in the command line (for example 12.8 or 45) are stored as strings. While using the numbers in the program, we need these conversion functions.
Following is a simple program which demonstrate the use of atoi function. This program prompts the user to enter an integer between 10-100, and checks if a valid integer is entered.
//This program demonstrate the use of atoi function
# include <iostream.h>
if (atoi(myInt) ==
The output of the program is as follows.
Enter an integer
between 10-100 : 45.5
NEXT>>>>>Lesson 29. String Functions