   READING IN FILES
  How come when i make a .dat file and put in an int called num and tried to read it from the file it in an int called number, number=0.Here is the code/*   Binary Files Tutorial.   Created by the Programming Ace.   www.UltimateGameProgramming.com   The purpose of this tutorial is to write data to a binary file.   The program will get (input) an account number, last name, first name, and   amount of money to enter in and saves the input in a binary file.  I''ve   tried really hard to keep this example as simple as possible for   learning purposes.  There will be 2 more binary tutorials in the   future, a part 2 to this and a tutorial on reading binary files.*/// Tip: Know how to open files regularly first.// LESSON: Binary Tutorial.// NOTE: Make sure you have a good unstanding of the beginner//  tutorials first before attempting this one.// This is a structure that will hold our client data information.// Each structure variable will hold a account number, lastname,// first name, and the balance.// Our input/output header file.#include#include// These are are using statements.  cerr is used to print out errors// to the screen instead of using cout, endl is just like the \n,// and the rest you should be familar with by now.  ios is used to choose// the ofstream object file mode.using std::cerr;using std::endl;using std::ios;using std::cout;using std::cin;// fstream header allow us to open files for output.#include <fstream>#include <iostream>// our using statments thats apart of fstream.  This allows us to open a file for output.using std::ofstream;using std::ifstream;int number;int num;int main(){ ofstream outCredit("credit.dat", ios::binary);   ifstream inCredit("credit,dat");    // Make sure everything is all good.  If the file didn''t open then the program will   // tell you so.   if(!outCredit) {    cerr << "File could not be opened." << endl;    exit(1); }// Get the account number...   cin >> num;   outCredit<>number; cout<<"The number that is supposed be equal to num"<   
  2 things I can see that are wrong.#1When you create your Input File Stream object(ifstream) you need to tell it that you are going to be reading a binary file like such:ifstream inFile;inFile.open("blah.dat", ios::binary);#2When reading from a binary file you can''t just use a token like you would a string file. Doing something like:inFile >> num;That won''t work as the file is written in binary and not in text form. Instead you have to read in using something like this:inFile.Read(num, "blah.dat", 4);4 being the number of bytes you wish to read in(int = 4 bytes). I may have the order wrong on that .Read function so check your MSDN but I believe that''s correct. It''s been a while since I''ve done binary reading and writing.Hope it helps. ;  ofstream outCredit("credit.dat", ios::binary);ifstream inCredit("credit,dat&quot;Check those two lines... (the filenames don''t match) ;std::ifstream fin(filename, std::ios::binary);if(fin.fail()){  std::cerr << "Failed to open file " << filename << " for binary output. Terminating..." << std::endl;  return -1;} // read data (example)fin.read(&num, sizeof(int)); fin.close();fin.clear(); 