In this article, we discuss useful utilities that you can use to convert, check and manipulate common data types in SplashKit programs.Written by Richard Denton on Oct 3 2018
SplashKit’s Utilities library provides a range of useful functions that can assist you with converting, checking and manipulating common data types in your SplashKit program.
These functions are useful in many areas of programming.
SplashKit provides two useful functions for handling the conversion of a std::string to either an int or a double.
Usage scenario: converting user input to an integer
Consider you want to write a program that accepts two numbers as input from a user, multiplies them, and outputs the result. One way to accomplish this is to use SplashKit’s convert_to_integer function.
The same can be achieved for decimal numbers, simply by swapping convert_to_integer with convert_to_double, and using the appropriate data types.
Checking if a string is a number
Another helpful set of functions provided by SplashKit’s utilities library is is_integer and is_number.
Consider the following.
Its output is as follows.
Usage scenario: accept user input as a number
SplashKit’s is_integer and is_number functions can be used to validate user input, ensuring the user always enters a valid data type.
Manipulating strings
In addition to the functionality provided by C++‘s standard string library, SplashKit’s utilities library provides some extra string manipulation functions that can assist you with manipulating std::string data.