You should use static_cast<char>(i)
to cast the integer i
to char
.
reinterpret_cast
should almost never be used, unless you want to cast one type into a fundamentally different type.
Also reinterpret_cast
is machine dependent so safely using it requires complete understanding of the types as well as how the compiler implements the cast.
For more information about C++ casting see:
- When should static_cast, dynamic_cast, const_cast and reinterpret_cast be used?
- http://www.cplusplus.com/doc/tutorial/typecasting/.
Related Posts:
- Convert char array to single int?
- C++ convert from 1 char to string?
- How can I convert a std::string to int?
- Easiest way to convert int to string in C++
- outputting ascii table in C++
- std::string to char*
- Conversion from string to char – c++
- Regular cast vs. static_cast vs. dynamic_cast
- What is an unsigned char?
- When to use reinterpret_cast?
- How to convert a char array to a string?
- Why unsigned int 0xFFFFFFFF is equal to int -1?
- How to convert a single char into an int [duplicate]
- std::string to char*
- How to convert a std::string to const char* or char*
- warning: ISO C++ forbids variable length array
- getline() does not work if used after some inputs
- How can I convert const char* to string and then back to char*?
- Convert char* to string C++
- C++ int float casting
- c++ parse int from string [duplicate]
- How to cast the size_t to double or int C++
- Multi-character constant warnings
- Integer to hex string in C++
- Comparing the values of char arrays in C++
- How to convert QString to int?
- Trying to use int in getline
- How to sort with a lambda?
- Function stoi not declared
- Function stoi not declared
- C++ compiler error c4430 “c++ doesnt support default int”
- C++ 2d char array to string
- Using cin for char array
- How do you append an int to a string in C++?
- How do I simply compare characters in C++?
- Using cin to input a single letter into a char
- I’m getting the error “stoi is not a member of std” in myprogramminglab [duplicate]
- Is “delete this” allowed in C++?
- What is a segmentation fault?
- How many spaces for tab character(\t)?
- How to create a dynamic array of integers
- How to create a dynamic array of integers
- Linker Error C++ “undefined reference ” [duplicate]
- How do I build a graphical user interface in C++? [closed]
- How do I build a graphical user interface in C++? [closed]
- convert a char* to std::string
- system(“pause”); – Why is it wrong?
- Pause Console in C++ program
- system(“pause”); – Why is it wrong?
- Pause Console in C++ program
- How to implement 2D vector array?
- Why the switch statement cannot be applied on strings?
- What is the difference between g++ and gcc?
- How to use setprecision in C++
- How to dynamically allocate arrays in C++
- What does (~0L) mean?
- How to dynamically allocate arrays in C++
- What is the best way to use a HashMap in C++?
- What is the best way to use a HashMap in C++?
- What are the differences between a pointer variable and a reference variable in C++?
- What is an undefined reference/unresolved external symbol error and how do I fix it?
- Sleep for milliseconds
- How to convert string to char array in C++?
- What is the difference between float and double?
- Why is “using namespace std;” considered bad practice?
- What is the easiest way to initialize a std::vector with hardcoded elements?
- What is a lambda expression in C++11?
- Vector of Vectors to create matrix
- How to throw a C++ exception
- How to generate a random number in C++?
- pinpointing “conditional jump or move depends on uninitialized value(s)” valgrind message
- What is an undefined reference/unresolved external symbol error and how do I fix it?
- How do I find the length of an array?
- Sleep for milliseconds
- How to convert string to char array in C++?
- C++ — expected primary-expression before ‘ ‘
- Using getline() with file input in C++
- What is the effect of extern “C” in C++?
- C++ Cout & Cin & System “Ambiguous” [closed]
- ld: symbol(s) not found for architecture x86_64 error
- C++ string to double conversion
- Why are #ifndef and #define used in C++ header files?
- g++ ld: symbol(s) not found for architecture x86_64
- What exactly is the difference between “pass by reference” in C and in C++?
- How to throw a C++ exception
- How to find out if an item is present in a std::vector?
- What is meant by Resource Acquisition is Initialization (RAII)?
- When to use extern “C” in simple words? [duplicate]
- What is `CString`?
- Floating point exception( core dump
- Initializing an array of objects
- Passing Arrays to Function in C++
- What does the explicit keyword mean?
- How do I print out the contents of a vector?
- Difference between != and =! with an example(in C++)
- Expression must have class type
- The static keyword and its various uses in C++
- How can I convert a char to int in Java? [duplicate]
- Passing an array by reference
- Unresolved external symbol in object files