read a .dat file in c++
<p>I am unable to read '.dat' file. I have tired all the possible ways and tired googling it but I could not find the solution. All it gives me is a null value for integer and a junk value for a string variable or char. This what I have written</p>

<pre><code>ifstream file;
file.open("data1.dat"); // I have also tried this way too like file.open("data1.dat", ios::binary, ios::in);
int data=0;
file &gt;&gt; data;
cout &lt;&lt; data &lt;&lt; endl;
system("pause");
return 0;  
</code></pre>

<p>I am using visual studio to compile this code. I am pretty sure that the pointer is entering into the data file but I don't know for what reason the data is not being read.</p>

<p>The .dat file consists of integer number per line ranging from 0, so I just need to read the file and get number from each line and should find the sum of all numbers in the file. The file contains number like
5,
468,
3200, 
32, etc.,. Each number is in a new line. The file can contain any number of records. <a href="http://i.stack.imgur.com/nAvXs.png" rel="nofollow">this how .dat file looks when opened using a notepad editor</a></p>