c++ cast to int code example
Example 1: how to convert from string to int in c++
#include <iostream>
#include <sstream>
using namespace std;
int main() {
string s = "999";
stringstream degree(s);
int x = 0;
degree >> x;
cout << "Value of x: " << x;
}
Example 2: casting to a double in c++
double x;
x = (double) 25;
Example 3: c++ casting
static_cast:
void* data;
pointer *pData = static_cast<pointer*>(data);
const_cast:
const char* characters;
const_cast<char*>(characters);
reinterpret_cast:
struct S1 { int a; } s1;
int* p1 = reinterpret_cast<int*>(&s1);