Console C++ API
Defines C++ wrapper to log/print text messages. More...
Classes
Type | Name |
---|---|
class | eosio::iostream |
Variables
Type | Name |
---|---|
static iostream | cout |
Functions
Detailed Description
This API uses C++ variadic templates and type detection to make it easy to print any native type. You can even overload the method for your own custom types.
Example:
print( "hello world, this is a number: ", 5 );
Variables Documentation
variable cout
iostream eosio::cout;
Functions Documentation
function print
void eosio::print(
const char * ptr
)
Prints string
Parameters:
- ptr - a null terminated string
function print
template<typename T, std::enable_if_t< std::is_integral< std::decay_t< T >>::value &&std::is_signed< std::decay_t< T >>::value, int >>
void eosio::print(
T num
)
Prints 8-128 bit signed integer
Parameters:
- num to be printed
Prints 8-128 bit unsigned integer
Parameters:
- num to be printed
function print
void eosio::print(
float num
)
Prints single-precision floating point number (i.e. float)
Parameters:
- num to be printed
function print
void eosio::print(
double num
)
Prints double-precision floating point number (i.e. double)
Parameters:
- num to be printed
function print
void eosio::print(
long double num
)
Prints quadruple-precision floating point number (i.e. long double)
Parameters:
- num to be printed
function print
template<size_t Size>
void eosio::print(
const fixed_bytes< Size > & val
)
Prints fixed_bytes as a hexidecimal string.
Prints fixed_bytes as a hexidecimal string
Parameters:
- val to be printed
function print
template<size_t Size>
void eosio::print(
fixed_bytes< Size > & val
)
Prints fixed_bytes as a hexidecimal string.
Prints fixed_bytes as a hexidecimal string
Parameters:
- val to be printed
function print
void eosio::print(
name name
)
Prints a 64 bit names as base32 encoded string
Parameters:
- name 64 bit name to be printed
function print
void eosio::print(
eosio::symbol_code sym_code
)
Prints a symbol_code
Parameters:
- sym_code symbol code to be printed
function print
template<typename T, std::enable_if_t<!std::is_integral< std::decay_t< T >>::value, int >>
void eosio::print(
T && t
)
Prints class object
Parameters:
- t to be printed
Precondition:
T must implements print() function
function print_f
void eosio::print_f(
const char * s
)
Prints null terminated string
Parameters:
- s null terminated string to be printed
function print_f
template<typename Arg, typename... Args>
void eosio::print_f(
const char * s,
Arg val,
Args... rest
)
Prints formatted string. It behaves similar to C printf/
Template parameters:
- Arg - Type of the value used to replace the format specifier
- Args - Type of the value used to replace the format specifier
Parameters:
- s - Null terminated string with to be printed (it can contains format specifier)
- val - The value used to replace the format specifier
- rest - The values used to replace the format specifier
Example:
print_f("Number of apples: %", 10);
function print
template<typename Arg, typename... Args>
void eosio::print(
Arg && a,
Args &&... args
)
Print out value / list of values
Template parameters:
- Arg - Type of the value used to replace the format specifier
- Args - Type of the value used to replace the format specifier
Parameters:
- a - The value to be printed
- args - The other values to be printed
Example:
const char *s = "Hello World!";
uint64_t unsigned_64_bit_int = 1e+18;
uint128_t unsigned_128_bit_int (87654323456);
uint64_t string_as_unsigned_64_bit = "abcde"_n;
print(s , unsigned_64_bit_int, unsigned_128_bit_int, string_as_unsigned_64_bit);
// Ouput: Hello World!100000000000000000087654323456abcde
function operator<<
template<typename T>
iostream& eosio::operator<<(
iostream & out,
const T & v
)
Overload c++ iostream
Template parameters:
- Arg - Type of the value used to replace the format specifier
- Args - Type of the value used to replace the format specifier
Parameters:
- out - Output strem
- v - The value to be printed
Returns:
iostream& - Reference to the input output stream
Example:
const char *s = "Hello World!";
uint64_t unsigned_64_bit_int = 1e+18;
uint128_t unsigned_128_bit_int (87654323456);
uint64_t string_as_unsigned_64_bit = "abcde"_n;
std::out << s << " " << unsigned_64_bit_int << " " << unsigned_128_bit_int << " " << string_as_unsigned_64_bit;
// Output: Hello World! 1000000000000000000 87654323456 abcde