writes formatted output to a file, using <<
#include <fstream> #include <iostream> #include <string> using namespace std; int main(){ char ch = 'x'; int j = 77; double d = 6.02; string str1 = "test"; string str2 = "this is a test"; ofstream outfile("fdata.txt"); outfile << ch << j << ' ' << d << str1 << ' ' << str2; cout << "File written\n"; return 0; }