Why do you think it is changing the underlying data buffer? That is only bad when you expose that buffer with c_str() and make changes directly to it. Here, tolower is called on each character in the string through the string's interface, so it is not a problem. You can use your first example.