 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
nadz Guest
|
Posted: Sun Sep 28, 2003 8:45 pm Post subject: reading from files with fstream |
|
|
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
|
|
| Back to top |
|
 |
Mike Wahler Guest
|
Posted: Sun Sep 28, 2003 8:54 pm Post subject: Re: reading from files with fstream |
|
|
"nadz" <jnadz (AT) lsol (DOT) net> wrote
| Quote: | 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
|
|
| Back to top |
|
 |
Kevin Goodsell Guest
|
Posted: Sun Sep 28, 2003 9:06 pm Post subject: Re: reading from files with fstream |
|
|
nadz wrote:
| Quote: | 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
--
My email address is valid, but changes periodically.
To contact me please use the address from a recent posting.
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|