473,386 Members | 1,819 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,386 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 3144
"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,...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: 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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.