Directly write into char* buffer of std::string
问题 So I have an std::string and have a function which takes char* and writes into it. Since std::string::c_str() and std::string::data() return const char* , I can't use them. So I was allocating a temporary buffer, calling a function with it and copying it into std::string . Now I plan to work with big amount of information and copying this buffer will have a noticeable impact and I want to avoid it. Some people suggested to use &str.front() or &str[0] but does it invoke the undefined behavior?