Skip to content

A class similar to Java's Scanner class which verifies user input

Notifications You must be signed in to change notification settings

aadityanaik/Scan

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Scan

A class similar to Java's Scanner class which verifies user input.

Installing

Add the class file (scan.hpp) into your include path. There is no need to build the file, since all the functions are defined in the class file itself.

Features-

Verifies the input and throws an exception if not matching.
Uses strict type checking to ensure that doubles and integers are not interchanged.
Takes care of the buffer clearing whenever wrong datatypes are entered.

Note

This class is strict on type-checking, so if the user is expecting an integer using

Scan input;
int x;

x = input.get<int>();

but a double is entered, the class will throw an exception. The same applies for the Scanner::next() function.

It is preferrable to use the Scanner::next() function to avoid unnecessary try blocks-

int x;

x = Scanner::next<int>("Integer expected");
// This gives "Integer expected" as the error message and
// keeps accepting inputs till it encounters an integer

x = Scanner::next<int>();
// This prints out the default message "Invalid datatype entered" as the error

// All error messages are printed to stderr


Demo

About

A class similar to Java's Scanner class which verifies user input

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages