/****************************************************************************** * This program simply writes the bytes 0 - 256 to a binary file. * * Copyright © 2021 Richard Lesh. All rights reserved. *****************************************************************************/ #undef NDEBUG #include "Utils.hpp" #include #include #include using namespace Utils; using namespace std; void write_binary_file(string filespec) { ofstream ofh(filesystem::path(filespec).c_str(), ios_base::binary); if (!ofh.good()) { throw ios_base::failure("Problem opening output file!"); } for (int b = 0; b <= 255; ++b) { ofh.put(b); } ofh.close(); } int main(int argc, char **argv) { if (argc != 2) { cout << "Syntax: " << argv[0] << " {filename}" << endl; exit(1); } string filespec(argv[1]); try { write_binary_file(filespec); } catch (ios_base::failure ex) { cout << "Error: " << Utils::exceptionMessage(ex) << endl; } return 0; }