#include #include #include int main(int argc, char* argv[]) { if ( argc < 2 ) return 1; std::string infilename(argv[1]); std::ifstream input(infilename, std::ofstream::binary); if ( ! input ) return 2; std::string outfilename = infilename.substr( 0, infilename.find_last_of('.') ) + "-.txt"; std::ofstream output(outfilename); if ( ! output ) return (void)(std::cerr << "error: could not create" << outfilename << std::endl), 3; size_t rows = 0, cols = 0; input.read(reinterpret_cast(&rows), sizeof(size_t)); input.read(reinterpret_cast(&cols), sizeof(size_t)); output << rows << ' ' << cols << std::endl << std::endl; for (size_t row = 0; row < rows; ++row) { for (size_t col = 0; col < cols; ++col) { double value = 0.0; input.read(reinterpret_cast(&value), sizeof(double)); output << value << (col < cols - 1 ? ' ' : '\n'); } } return 0; }