473,386 Members | 1,973 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.

going back to the top line in input file

i am reading a file like this

ifstream infile(somefilenamestring.c_str())

while (infile >> myvariable)
{
/* do some interesting stuff */
}

now... if i want to get back to the first line of the file after i
executed this loop, what should i do ? is there a special thing that
needs to be done?

Nov 22 '05 #1
2 1379
ma******@gmail.com wrote:
i am reading a file like this

ifstream infile(somefilenamestring.c_str())

while (infile >> myvariable)
{
/* do some interesting stuff */
}

now... if i want to get back to the first line of the file after i
executed this loop, what should i do ? is there a special thing that
needs to be done?


You could use seekg.

--John Ratliff
Nov 22 '05 #2
John Ratliff wrote:
ma******@gmail.com wrote:
i am reading a file like this

ifstream infile(somefilenamestring.c_str())

while (infile >> myvariable)
{
/* do some interesting stuff */
}

now... if i want to get back to the first line of the file after i
executed this loop, what should i do ? is there a special thing that
needs to be done?


You could use seekg.


Don't forget to call clear() before seekg().
Nov 22 '05 #3

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

Similar topics

65
by: Miklós | last post by:
Ok, seems like we have @decorators. It's a nice tribute to Intercal. But I'd prefer #decorators. We have metaclasses for pleasure brain-melting. We have generators, new-style classes and...
2
by: Andrew Rich | last post by:
Howdy, I have a need to do this :- 1. find a match 2. go back three lines 3. read out lines 1 2 3 eg
4
by: Andre | last post by:
Hi, This is 'test.htm' --------------- <form name=totd> <input name="ud" type="hidden" value="" > </form>
0
by: Matthew Heironimus | last post by:
According to the XML 1.0 (Third Edition) W3C Recommendation (http://www.w3.org/TR/2004/REC-xml-20040204/#sec-line-ends) all #xD, #xA, and #xD#xA character combinations should be converted to a...
1
by: Matthew Heironimus | last post by:
According to the XML 1.0 (Third Edition) W3C Recommendation (http://www.w3.org/TR/2004/REC-xml-20040204/#sec-line-ends) all #xD, #xA, and #xD#xA character combinations should be converted to a single...
1
by: ricky | last post by:
I am a student doing internship. Iam doing a project. I need to remove or update a line in the file. So far 1.I can read from file 2. I can write to the file 3. I can find the string in the file...
5
by: barnetod | last post by:
I am trying to open a text file designated by the user. Then I want to change all lower case values to capital letters. Then write file. I am stuck and can not change the characters or am...
3
pradeepjain
by: pradeepjain | last post by:
<html> <head> </head> <body> <?php $filehandle = fopen("welcome.txt","r"); if(filesize("welcome.txt")=='0') {
11
by: JWest46088 | last post by:
I'm having difficulty trying to figure out how to print a text file from a hash table one line at a time. I have the text file read into the hash table and can print the text file all at once, but I...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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?
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
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...
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.