I want to write a std::string variable I am accepting from the user to a file. I tried using the write() method and it writes to the file. But when
std::string
write()
Assuming you're using a std::ofstream to write to file, the following snippet will write a std::string to file in human readable form:
std::ofstream
std::ofstream file("filename"); std::string my_string = "Hello text in file\n"; file << my_string;