Search
 
SCRIPT & CODE EXAMPLE
 

CPP

C++ int to char*

std::string s = std::to_string(number);
char const *pchar = s.c_str();  //use char const* as target type
Comment

integer to char c++

// for example you have such integer
int i = 3;

// and you want to convert it to a char so that
char c = '3';

what you need to do is, by adding i to '0'. The reason why it works is because '0' actually means an integer value of 48. '1'..'9' means 49..57. This is a simple addition to find out corresponding character for an single decimal digit integer:

i.e. char c = '0' + i;

If you know how to convert a single decimal digit int to char, whats left is how you can extract individual digit from a more-than-one-decimal-digit integer

it is simply a simple math by making use of / and %

int i = 123 % 10;  // give u last digit, which is 3
int j = 123 / 10;  // give remove the last digit, which is 12
The logic left is the homework you need to do then.
Comment

How to turn an integer variable into a char c++

char aChar = '0' + i;
Comment

PREVIOUS NEXT
Code Example
Cpp :: card validator c++ 
Cpp :: remove element from vector 
Cpp :: c++ 14 for sublime windoes build system 
Cpp :: new c++ 
Cpp :: c++ contains 
Cpp :: c preprocessor operations 
Cpp :: iterate through list c++ 
Cpp :: tree to array c++ 
Cpp :: error handling in c++ 
Cpp :: c++ hash combine 
Cpp :: Max element in an array with the index in c++ 
Cpp :: mac emoji shortcut 
Cpp :: How do I read computer current time in c++ 
Cpp :: c++ find object in vector by attribute 
Cpp :: pointer cpp 
Cpp :: maxheap cpp stl 
Cpp :: c++ reverse part of vector 
Cpp :: explicit c++ 
Cpp :: unpack tuple c++ 
Cpp :: why do we use pointers in c++ 
Cpp :: how to sort array in c++ stockoverflow 
Cpp :: c++ loop trhought object 
Cpp :: pointers and arrays in c++ 
Cpp :: program to swap max and min in matrix 
Cpp :: char array declaration c++ 
Cpp :: google test assert exception 
Cpp :: declare a tab c++ 
Cpp :: initialize a vector with same values 
Cpp :: c++ write string 
Cpp :: concatenate string in cpp 
ADD CONTENT
Topic
Content
Source link
Name
9+2 =