write string to file c++ 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: c++ write string
#include <iostream>
int main() {
std::cout << "Hello" << std::endl; //endl = end line/new line
// or
printf("hello");
}