Amit Kumar
Amit Kumar

Reputation: 113

using a user defined function in place of cin in c++

What is the use of this function? I mean,the program where I saw this function,they used this in place of std input in c++,how does it work?

int scan()
{
    int n=0,ch =get();
    while(ch<'0'||ch>'9')
       ch = get();
    while(ch>='0'&& ch<='9')
    {
        n= n*10 +ch -'0';
        ch = get();
    }
    return n;
}

Upvotes: 1

Views: 156

Answers (1)

Gnqz
Gnqz

Reputation: 3382

Basicly it reads the standart input until you type in some digits, then it returns the value composed of the digits after you type something different than a digit. It could be used to filter the first number in some input.

Upvotes: 1

Related Questions