I was searching through SO and I came across this question of assigning fixed length character array to a string. But what I want is the reverse operation, assigning a string to a fixed length character array. For eg if I have
char name[20];
name = "John";
I get a compile time error saying I am assigning char array[4] to char array[20].
How can I get this done ?
string::c_str()instead."John"is not astd::string. It is a string literal, and the data type ischar [5], notstd::string. C++ does not give any special treatment tostd::string(and most other library classes and functions).