C++ examples for Data Type:Cast
To convert the value of an expression to a given type, you write the following:
static_cast<type_to_convert_to>(expression)
Here's another example of the use of static_cast<>():
#include <iostream> #include <cmath> // For square root function using std::cout;/*from w ww. j a va2 s. c o m*/ int main() { double value1 {10.5}; double value2 {15.5}; int whole_number {static_cast<int>(value1) + static_cast<int>(value2)}; cout << whole_number; }