fork download
  1. #include <iostream>
  2. #include <sstream>
  3. #include <fstream>
  4. #include <string.h>
  5.  
  6. using namespace std;
  7.  
  8. int main(int argc, char ** argv) {
  9.  
  10. ofstream outputData;
  11. stringstream stringFix;
  12. char fileBase[150] = "outputData";
  13. stringFix << "2223" << ".txt";
  14. std::string filename(strcat(fileBase, stringFix.str().c_str()));
  15. outputData.open(filename);
  16.  
  17. if(!outputData.is_open())
  18. return 0; // ERR
  19.  
  20. int i = 0;
  21. while (i < 3) {
  22. //Some data is written to the stream, similar in format to:
  23. outputData << "Trump: " << "Hello dear" << endl;
  24. i++;
  25. }
  26.  
  27. outputData.flush();
  28. outputData.close();
  29.  
  30. cout << "Should have written successfully..." << endl;
  31.  
  32. }
Success #stdin #stdout 0s 3472KB
stdin
Standard input is empty
stdout
Standard output is empty