Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Got another one...

Status
Not open for further replies.

eyesrglazed

Programmer
Jul 14, 2005
20
US
I am now trying to write some code that reads and writes to files in a loop.

Code:
#include <iostream>
#include <fstream>

using namespace std;

int main()
{
    ifstream inFile;
    ofstream outFile;

    inFile.open("temp.dat");
    .
    .
    //Grab strings
    inFile.close();

    outFile.open("results.dat");
    .
    .
    //Write strings
    outFile.close();

    return 0;
}

I want this to work in a loop, but the reading marker for the inFile doesn't reset itself (go back up to the beginning of the file). Can anyone help me?
 
infile.seekg (0, ios::beg);

will move your file pointer to the beginning of hte file.. but i dont' really know what you want to do! plz explain in english and also show how you are reading from the file..
 
The program takes info and stores it in a temp.dat file.

Information from a info.dat file determines what it reads.
Here is an example of this :

str0 str1 str2 str3 str4 //Row1
str5 str6 str7 str8 str9 //Row2

The strings in row1 determine what the program writes in temp.dat. After it is finished with the 1st row, I want it to loop and do the same thing with the 2nd row. This means writing over the stuff in temp.dat.

I thought that reseting the reading marker in temp.dat would fix the problem. How can I do this?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top