• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 211
  • Last Modified:

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;
1 Solution
Jaime OlivaresSoftware ArchitectCommented:
int myInt;

ifstream >> myInt;
s177267Author Commented:
ok looks good, but testfile >> myInt, it doesn't metter.
Can You know maybe hot to read mode than only first line :)
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.

Join & Write a Comment

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now