Please tell me how to convert int to char in c++ style? The content in str1 is "\001", while the content in str2 is "1"; Can I use static_cast to get the same result as str2?
The code is as follows:
#include <iostream>
using namespace std;
int main()
{
int a = 1;
string str1;
string str2;
str1.push_back(static_cast<char>(a));
str2.push_back('0' + a);
cout << str1 << str2;
return 0;
}