Mega Code Archive

 
Categories / C++ Tutorial / File Stream
 

Open a binary file

#include <iostream> #include <fstream> using namespace std; int main(int argc, char *argv[]) {   char ch;   ifstream in("test.txt", ios::in | ios::binary);   if(!in) {     cout << "Cannot open file.";     return 1;   }   while(in) { // in will be false when eof is reached     in.get(ch);     if(in) cout << ch;   }   return 0; } R 9.9 T 9.9 M 4.8