Table of Contents

C - C++ Files - Write string to file

write_string_to_file.hpp

#pragma once
 
#include <string>
 
void write_string_to_file(std::string filename, std::string content);

write_string_to_file.cpp

#include "write_string_to_file.hpp"
#include <sstream>
#include <fstream>
 
void write_string_to_file(std::string filename, std::string content)
{
  std::ofstream(filename) << content;
}

References

https://en.cppreference.com/w/cpp/io/basic_ostream/operator_ltlt