Hi, Im trying to write a program to read in a textfile and convert it its binary represntation. I was under the impression that c++ does this automatically if you construct an ofstream using ios_base::binary. Can someone tell me how to do this properly ? here is my code -
Code:#include<iostream> #include<fstream> #include<string> using namespace std; int main() { string filename; cout << "Enter Filename: "; cin >> filename; ifstream infile; infile.open(filename.c_str()); if(infile.fail()){ cout << "File not found\n"; exit(1); } else { cout << "Converting file..." << endl; } filename += "_b.txt"; ofstream outfile(filename.c_str(),ios_base::binary); string buffer; while(getline(infile,buffer)) outfile << buffer; cout << "File Conversion Complete.." << endl; outfile.close(); infile.close(); return 0; }



LinkBack URL
About LinkBacks



