Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifndef SK_UTILS_H
- #define SK_UTILS_H
- /************************************************************/
- /* Tools for converting to and from */
- /* C/C++ strings into basic types */
- /* bool, int and float */
- /************************************************************/
- #include <sstream>
- #include <iomanip> // for setprecision(n)
- #include <stdlib.h> // for itoa()/itof()
- using namespace std; // because I like readable code!
- namespace sku
- {
- // default floating point precision
- extern int8_t DFP;
- // floating point precision value
- extern int8_t FP;
- void setFP(uint16_t p = DFP);
- /************************************************************/
- /* To C string */
- /************************************************************/
- const char* tocs(bool, bool alpha = false); // From bool
- const char* tocs(int32_t); // From int
- const char* tocs(float, uint8_t p = FP); // From float
- const char* tocs(string); // From C++ string - for convenience
- /************************************************************/
- /* To C++ string */
- /************************************************************/
- string tos(bool, bool alpha = false); // From bool
- string tos(int32_t); // From int
- string tos(uint32_t);
- string tos(int64_t);
- string tos(uint64_t); // From int
- string tos(float, uint8_t p = FP); // From float
- string tos(double, uint8_t p = FP);
- string tos(const char*); // From C string
- /************************************************************/
- /* To Bool */
- /************************************************************/
- bool stob(const char*); // C string to bool
- bool stob(string); // C++ string to bool
- /************************************************************/
- /* To Int */
- /************************************************************/
- int32_t stoi(const char* c); // C string to int
- int32_t stoi(string); // C++ string to int
- /************************************************************/
- /* To Float */
- /************************************************************/
- float stof(const char*); // C string to float (double?)
- float stof(string); // C++ string to float (double?)
- } // namespace sku
- #endif
Advertisement
Add Comment
Please, Sign In to add comment