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