473,383 Members | 1,877 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

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
Jul 19 '05 #1
2 3143
"nadz" <jn***@lsol.net> wrote in message
news:vn************@corp.supernews.com...
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
Jul 19 '05 #2
nadz wrote:
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.

Jul 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: fabrice | last post by:
Hello, I've got trouble reading a text file (event viewer dump) by using the getline() function... After 200 - 300 lines that are read correctly, it suddenly stops reading the rest of the...
2
by: Brian Ward | last post by:
First: sorry as a relative newbie for previously not including code. My question: Reading C++ books I almost always find programs such as the one below give the following type of code for reading...
4
by: reddy | last post by:
Hai, in my program i am creating two files, and displaying that files, but i am getting some errors like, "name' : is not a member of 'fstream'"? in that i am not getting some fields from what i...
7
by: Daniel Moree | last post by:
I'm working on a program that must first establish if the file exists in the program directory then it must open if for reading, read each line and set the variables then the program goes on about...
6
by: GG | last post by:
Is this public static method thread safe. //Receives a file name as a parameter //and returns the contents of that file as a string public static string FileToStr(string fileName) { FileStream...
2
by: Sabin Finateanu | last post by:
Hi I'm having problem reading a file from my program and I think it's from a procedure I'm using but I don't see where I'm going wrong. Here is the code: public bool AllowUsage() { ...
4
by: Agos | last post by:
I'm trying to learn VC++.NET. I used till now Borland C++ Builder 6. I had a program starting like this: #include <fstream.h> #define TEMP_FILES 200 ...... ....... fstream chunk_file; With...
7
by: jccorreu | last post by:
I've got to read info from multiple files that will be given to me. I know the format and what the data is. The thing is each time we run the program we may be using a differnt number of files,...
0
by: lion | last post by:
I have in my programm three files: SCANNER.CPP,tst_scanner.cpp and scaner.h i need read and write from text file which is glopal. how i can do it? the strange things if i put all programm in one...
7
by: random guy | last post by:
Hi, I'm writing a program which creates an index of text files. For each file it processes, the program records the start and end positions (as returned by tellg()) of sections of interest,...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.