How to get int from file

How can I read the data from file, but these data have to be as int, not as char. I need some value which is number stores in file.


#include <iostream.h>
#include <fstream.h>
#include <stdlib.h>

int main () {
 char buffer[256];
 ifstream testfile ("test.txt");
 if (! testfile.is_open())
 { cout << "Error opening file"; exit (1); }

 while (! testfile.eof() )
 {
   testfile.getline (buffer,100);
   cout << buffer << endl;
 }
 return 0;
}
s177267Asked:
Who is Participating?
 
Jaime OlivaresConnect With a Mentor Software ArchitectCommented:
int myInt;

ifstream >> myInt;
0
 
s177267Author Commented:
ok looks good, but testfile >> myInt, it doesn't metter.
Can You know maybe hot to read mode than only first line :)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.