12345678910
std::ifstream infile(inputfilename.c_str(), ios::binary); std::ofstream outfile(outputfilename.c_str(), ios::binary|ios::trunc); // get the size of inputfile in byte streampos fsize = 0; inputfile.seekg(0,ios::end); fsize = inputfile.tellg(); inputfile.seekg(0); outfile.write(reinterpret_cast<char *>(inputfile.rdbuf()) , sizeof(fsize));
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
int main(int argc, char * argv[]) { /// process command line arguments string input(argv[1]); string outputfile(argv[2]); //End of argument processing //****************************/ size_t cols = 3; size_t rows = 0; size_t face = 0; ifstream inputfile(input.c_str(), ios::binary); // get the number of lines as # rows string line; while(getline(inputfile, line)) { ++rows; } inputfile.clear(); ofstream outfile(outputfile.c_str(), ios::binary|ios::trunc); // PLY header outfile << "ply" << std::endl << "format binary_little_endian 1.0" << std::endl << "comment Lee Seongjoo at Yonsei University" << std::endl << "obj_info num_cols " << cols << std::endl << "obj_info num_rows " << rows << std::endl << "element vertex " << rows << std::endl << "property float x\n" << "property float y\n" << "property float z\n" << "element face " << face << std::endl << "property list uchar int vertex_indices\n" << "end_header\n"; // get the size of inputfile streampos fsize=0; inputfile.seekg(0, ios::end); fsize = inputfile.tellg(); inputfile.seekg(0); /* supposedly write the content of inputfile as raw binary but not quite successful yet */ outfile.write(reinterpret_cast<char *>(inputfile.rdbuf()), sizeof(fsize)); inputfile.close(); outfile.close(); return 0; }