0

How do i make a dummy file?

I'm using Visual C++ for a form and I need it to make a dummy file. I know how to use things like fstream to write to files but how can I do it so that I know the exact size of the resulting file?

I already tried fstuil but that's a CMD command (yes i know you can use system()) whereas i want pure c++.

pablo285
  • 2,460
  • 4
  • 14
  • 38
big boi
  • 47
  • 5

1 Answers1

1

Try this (creates a 1MB file):

#include <fstream>

int main()
{
    std::ofstream ofs("foo.bar", std::ios::binary | std::ios::out);
    ofs.seekp((1024*1024) - 1);
    ofs.write("", 1);
}
pablo285
  • 2,460
  • 4
  • 14
  • 38