Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 209
  • 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;
}
0
s177267
Asked:
s177267
1 Solution
 
Jaime OlivaresSoftware 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

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

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