write string to file cpp code example
Example 1: c++ stream string into fiel
#include <fstream>
#include <string>
#include <iostream>
int main()
{
std::string input;
std::cin >> input;
std::ofstream out("output.txt");
out << input;
out.close();
return 0;
}
Example 2: write to file in C++
ofstream myfile;
myfile.open("file.txt");
myfile << "write this to file"
Example 3: c++ write string
#include <iostream>
int main() {
std::cout << "Hello" << std::endl; //endl = end line/new line
// or
printf("hello");
}