Size of temp is just one char. If you try to write more, you go out of bounds and thus get an error.
You should declare char temp[4];
Though if you want work with strings, you should use std::string.
The second one is no better. The type of string literals is const char*, even though compilers allow assigning them to normal char*. The thing is that you can't write to them at all. And even if you could, you'd still be writing out of bounds.
As I said, use std::string. You won't be able to immediately write wherever you want,but you car resize them at any time.