I would like to know if writing to the same file with std::string and std::wstring objects is safe for sure. I have a snippet like this:
void foo(std::string&& msg) {
std::ofstream file{ "log.txt", std::ios_base::app };
file << msg << '\n';
}
void foo(std::wstring&& msg) {
std::wofstream file{ "log.txt", std::ios_base::app };
file << msg << '\n';
}
int main() {
foo(std::string{ "sample string text" });
foo(std::wstring{ L"sample wstring text" });
}
I am not sure if there are no problems with encoding when using this code or these problems may occur in specific situations. Has anyone an idea for dangers associated with it?