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]
- What are the differences between a pointer variable and a reference variable in C++?
- What is the effect of extern “C” in C++?
- What exactly is the difference between “pass by reference” in C and in C++?
- What is `CString`?
- Difference between != and =! with an example(in C++)
- Unresolved external symbol in object files
- How do sizeof(arr) / sizeof(arr[0]) work?
- When does a process get SIGABRT (signal 6)?
- Logical XOR operator in C++?
- C++ – Decimal to binary converting
- Alternative to itoa() for converting integer to string C++?
- 1e-9 or -1e9, which one is correct?
- Returning an empty string : efficient way in c++
- invalid conversion from ‘const char*’ to ‘char*’
- Evaluate a string with a switch in C++ [duplicate]
- Expected initializer before function name
- Inheriting constructors
- Pass a vector by reference C++
- lvalue required as left operand of assignment – Array
- What is uintptr_t data type
- Why do we use volatile keyword? [duplicate]
- terminate called after throwing an instance of ‘std::out_of_range’
- What does “missing template argument” mean?
- undefined reference to ‘std::cout’
- warning: control may reach end of non-void function
- what does “error : a nonstatic member reference must be relative to a specific object” mean?
- Can I output a one channel image acquired from camera into a winAppi window?
- Difference in make_shared and normal shared_ptr in C++
- VC++ fatal error LNK1168: cannot open filename.exe for writing
- Reading integers from file and store them in array C++ [closed]
- Uninitialised value was created by a stack allocation
- C++ Image Processing Libraries
- Printing the correct number of decimal points with cout
- error C2011: ” : ‘class’ type redefinition
- read word by word from file in C++
- How to replace all occurrences of a character in string?
- Deleting an object in C++
- Appending a vector to a vector
- C++ Expression must have pointer-to-object type
- C++ “Access violation reading location” Error
- Getting error: ISO C++ forbids declaration of with no type
- IntelliSense: the object has type qualifiers that are not compatible with the member function
- codingbat-like site for C++
- extra qualification error in C++
- How to convert ASCII value into char in C++?
- How to alphabetically sort strings?
- Function definition not found for a function declared inside unnamed namespace – how to resolve? (Visual Studio 2015)
- How do I check if a C++ std::string starts with a certain string, and convert a substring to an int?
- How do I get the type of a variable?
- What is the meaning of a C++ Wrapper Class?
- terminate called after throwing an instance of ‘std::out_of_range’ what(): basic_string::substr
- error C2106: ‘=’ : left operand must be l-value
- multiple definitions error in c++ and solution to solve this issue
- C++ Void Function with File Stream Error
- Why is this vector iterator not incrementable?
- glibc detected : double free or corruption
- What is the best way to develop a C++ web application?
- How to install Visual Studio Build Tools 2010 on Visual Studio 2015 Community?
- Throwing out of range exception in C++
- Is null reference possible?
- Link error “undefined reference to `__gxx_personality_v0′” and g++ [duplicate]
- How to use bitmask?
- -Error reading characters of string