Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How to get int from file

Posted on 2004-08-27
2
Medium Priority
?
205 Views
Last Modified: 2010-04-01
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
Comment
Question by:s177267
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 55

Accepted Solution

by:
Jaime Olivares earned 40 total points
ID: 11912991
int myInt;

ifstream >> myInt;
0
 

Author Comment

by:s177267
ID: 11914079
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

597 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question