#include <iostream>
#include <sstream>
#include <fstream>
#include <string.h>
using namespace std;
int main(int argc, char ** argv) {
ofstream outputData;
stringstream stringFix;
char fileBase[150] = "outputData";
stringFix << "2223" << ".txt";
std::string filename(strcat(fileBase, stringFix.str().c_str()));
outputData.open(filename);
if(!outputData.is_open())
return 0; // ERR
int i = 0;
while (i < 3) {
//Some data is written to the stream, similar in format to:
outputData << "Trump: " << "Hello dear" << endl;
i++;
}
outputData.flush();
outputData.close();
cout << "Should have written successfully..." << endl;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8c3N0cmVhbT4KI2luY2x1ZGUgPGZzdHJlYW0+CiNpbmNsdWRlIDxzdHJpbmcuaD4KCnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgppbnQgbWFpbihpbnQgYXJnYywgY2hhciAqKiBhcmd2KSB7ICAgIAoKICBvZnN0cmVhbSBvdXRwdXREYXRhOwogIHN0cmluZ3N0cmVhbSBzdHJpbmdGaXg7CiAgY2hhciBmaWxlQmFzZVsxNTBdID0gIm91dHB1dERhdGEiOwogIHN0cmluZ0ZpeCA8PCAiMjIyMyIgPDwgIi50eHQiOwogIHN0ZDo6c3RyaW5nIGZpbGVuYW1lKHN0cmNhdChmaWxlQmFzZSwgc3RyaW5nRml4LnN0cigpLmNfc3RyKCkpKTsKICBvdXRwdXREYXRhLm9wZW4oZmlsZW5hbWUpOwoKICBpZighb3V0cHV0RGF0YS5pc19vcGVuKCkpCgkgIHJldHVybiAwOyAvLyBFUlIKCiAgaW50IGkgPSAwOwogIHdoaWxlIChpIDwgMykgewogICAgLy9Tb21lIGRhdGEgaXMgd3JpdHRlbiB0byB0aGUgc3RyZWFtLCBzaW1pbGFyIGluIGZvcm1hdCB0bzoKICAgIG91dHB1dERhdGEgPDwgIlRydW1wOiAiIDw8ICJIZWxsbyBkZWFyIiA8PCBlbmRsOwoJaSsrOwogIH0KCiAgb3V0cHV0RGF0YS5mbHVzaCgpOwogIG91dHB1dERhdGEuY2xvc2UoKTsKCiAgY291dCA8PCAiU2hvdWxkIGhhdmUgd3JpdHRlbiBzdWNjZXNzZnVsbHkuLi4iIDw8IGVuZGw7Cgp9