how to convert from int to char*?

In C++17, use std::to_chars as: std::array<char, 10> str; std::to_chars(str.data(), str.data() + str.size(), 42); In C++11, use std::to_string as: std::string s = std::to_string(number); char const *pchar = s.c_str(); //use char const* as target type And in C++03, what you’re doing is just fine, except use const as: char const* pchar = temp_str.c_str(); //dont use cast

How to convert const char* to char* in C?

To be safe you don’t break stuff (for example when these strings are changed in your code or further up), or crash you program (in case the returned string was literal for example like “hello I’m a literal string” and you start to edit it), make a copy of the returned string. You could use … Read more