to char c+ code example
Example 1: convert string to char c++
std::string str = "Hello World";
char buffer[50];
strcpy(buffer, str.c_str());
std::cout << buffer;
Example 2: integer to char c++
int i = 3;
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;
int j = 123 / 10;
The logic left is the homework you need to do then.
Example 3: COnvert string to char * C++
#include <bits/stdc++.h>
using namespace std;
int main()
{
string s = "geeksforgeeks";
int n = s.length();
char char_array[n + 1];
strcpy(char_array, s.c_str());
for (int i = 0; i < n; i++)
cout << char_array[i];
return 0;
}