BEEP-8 Helper Lib 1.0.0
Loading...
Searching...
No Matches
tostr.h File Reference

Utility functions for converting various data types to std::string. More...

#include <string>

Go to the source code of this file.

Functions

std::string tostr (int val)
 Converts an integer to a std::string.
 
std::string tostr (unsigned int val)
 Converts an unsigned integer to a std::string.
 
std::string tostr (long val)
 Converts a long integer to a std::string.
 
std::string tostrhex (unsigned long val)
 Converts an unsigned long integer to a hexadecimal std::string.
 
std::string tostr (void *val)
 Converts a pointer to a hexadecimal std::string.
 
std::string tostr (unsigned long val)
 Converts an unsigned long integer to a std::string.
 
std::string tostr (long long val)
 Converts a long long integer to a std::string.
 
std::string tostr (unsigned long long val)
 Converts an unsigned long long integer to a std::string.
 
std::string tostr (float val)
 Converts a float to a std::string.
 
std::string tostr (double val)
 Converts a double to a std::string.
 
std::string tostr (long double val)
 Converts a long double to a std::string.
 
std::string tostr (const char *sz)
 Converts a C-style string to a std::string.
 
std::string tostr (std::string str_)
 Returns the given std::string.
 

Detailed Description

Utility functions for converting various data types to std::string.

This header file provides a set of inline functions to convert different data types to their string representations using std::to_string and custom formatting. The provided functions handle conversions for integral types, floating-point types, pointers, and C-style strings.

Example usage:

int num = 42;
std::string str = tostr(num); // Converts integer to string
float fnum = 3.14f;
std::string fstr = tostr(fnum); // Converts float to string
void* ptr = static_cast<void*>(&num);
std::string ptrstr = tostr(ptr); // Converts pointer to hexadecimal string
const char* cstr = "hello";
std::string str = tostr(cstr); // Converts C-style string to std::string
Definition cstr.h:109

Function Documentation

◆ tostr() [1/12]

std::string tostr ( const char * sz)
inline

Converts a C-style string to a std::string.

Parameters
szThe C-style string to convert.
Returns
The std::string representation of the C-style string.

◆ tostr() [2/12]

std::string tostr ( double val)
inline

Converts a double to a std::string.

Parameters
valThe double value to convert.
Returns
The string representation of the double.

◆ tostr() [3/12]

std::string tostr ( float val)
inline

Converts a float to a std::string.

Parameters
valThe float value to convert.
Returns
The string representation of the float.

◆ tostr() [4/12]

std::string tostr ( int val)
inline

Converts an integer to a std::string.

Parameters
valThe integer value to convert.
Returns
The string representation of the integer.

◆ tostr() [5/12]

std::string tostr ( long double val)
inline

Converts a long double to a std::string.

Parameters
valThe long double value to convert.
Returns
The string representation of the long double.

◆ tostr() [6/12]

std::string tostr ( long long val)
inline

Converts a long long integer to a std::string.

Parameters
valThe long long integer value to convert.
Returns
The string representation of the long long integer.

◆ tostr() [7/12]

std::string tostr ( long val)
inline

Converts a long integer to a std::string.

Parameters
valThe long integer value to convert.
Returns
The string representation of the long integer.

◆ tostr() [8/12]

std::string tostr ( std::string str_)
inline

Returns the given std::string.

Parameters
str_The std::string to return.
Returns
The input std::string.

◆ tostr() [9/12]

std::string tostr ( unsigned int val)
inline

Converts an unsigned integer to a std::string.

Parameters
valThe unsigned integer value to convert.
Returns
The string representation of the unsigned integer.

◆ tostr() [10/12]

std::string tostr ( unsigned long long val)
inline

Converts an unsigned long long integer to a std::string.

Parameters
valThe unsigned long long integer value to convert.
Returns
The string representation of the unsigned long long integer.

◆ tostr() [11/12]

std::string tostr ( unsigned long val)
inline

Converts an unsigned long integer to a std::string.

Parameters
valThe unsigned long integer value to convert.
Returns
The string representation of the unsigned long integer.

◆ tostr() [12/12]

std::string tostr ( void * val)
inline

Converts a pointer to a hexadecimal std::string.

Parameters
valThe pointer value to convert.
Returns
The hexadecimal string representation of the pointer.

◆ tostrhex()

std::string tostrhex ( unsigned long val)
inline

Converts an unsigned long integer to a hexadecimal std::string.

Parameters
valThe unsigned long integer value to convert.
Returns
The hexadecimal string representation of the unsigned long integer.