reading from files with fstream

N

nadz

Here is the problem I am having. Right now i need to open a file and read
from it using fstream. I can do that. However, the file I am reading from
consists of two numbers at that top and then a series of other characters.
The other characters I can do with no problem however, I do not know how to
read the numbers as ints. I want to send them to integer variables. I have
been using the get(<variable name>) to extract the characters with no
problem. If somebody could help me I would be most appreciative. Thanks in
advance!!!


~Justin
 
M

Mike Wahler

nadz said:
Here is the problem I am having. Right now i need to open a file and read
from it using fstream. I can do that. However, the file I am reading from
consists of two numbers at that top and then a series of other characters.
The other characters I can do with no problem however, I do not know how to
read the numbers as ints. I want to send them to integer variables. I have
been using the get(<variable name>) to extract the characters with no
problem. If somebody could help me I would be most appreciative. Thanks in
advance!!!


stream >> number;

It's much easier to help if you post your code.

-Mike
 
K

Kevin Goodsell

nadz said:
Here is the problem I am having. Right now i need to open a file and read
from it using fstream. I can do that. However, the file I am reading from
consists of two numbers at that top and then a series of other characters.
The other characters I can do with no problem however, I do not know how to
read the numbers as ints. I want to send them to integer variables. I have
been using the get(<variable name>) to extract the characters with no
problem. If somebody could help me I would be most appreciative. Thanks in
advance!!!

It depends heavily on your file format, but in many cases you can just
do this:

ifstream_var >> int_var;

-Kevin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top