fork download
  1. #include <iostream>
  2. #include <fstream>
  3. #include <string>
  4.  
  5. int main()
  6. {
  7. std::string filename("file.txt");
  8. std::ofstream ofs;
  9. ofs.open(filename, std::ios::binary);
  10. const int n = 4, array_size = 3, half = n * array_size;
  11.  
  12. for (int i = 0; i < n; ++i)
  13. {
  14. const int position = ofs.tellp();
  15. ofs.write((n % 2 == 0) ? "abc" : "XYZ", array_size);
  16. ofs.seekp(position + half);
  17. ofs.write((n % 2 == 0) ? "ABC" : "xyz", array_size);
  18. ofs.seekp(position + array_size);
  19. }
  20.  
  21. ofs.close();
  22. std::cin.get();
  23. return 0;
  24. }
Success #stdin #stdout 0s 3460KB
stdin
Standard input is empty
stdout
Standard output is empty