I have the code(below) but I can't get the program to close data2.txt and opne it again. Is there a way to reset the starting read position? I want it read through the file for as many times as I want, without ever editing the file.

#include <fstream>

#include <string>

#include <iostream>

using namespace std;

ifstream file_in;

ifstream file_in2;

ofstream file_out;

int find_num();

void open_html();

void open_wrote();

void close_html();

void close_wrote();

void do_write();

int main()

{

// open streams for IO

int number_of_ids=0;

number_of_ids=find_num();

//char buffer2[15000];

file_in2.open("data2.txt");

for(int v=0;v<=3;v++)

{

file_in2.open("data2.txt");

do_write();

cout<<"Value of id's "<<number_of_ids<<endl;

cout<<"Iteration number : "<<v<<endl;

file_in2.close();

}

return 0;

}

int find_num()

{

int num=0;

ifstream in_file3;

in_file3.open("data.txt");

string id;

for(;;)

{

in_file3>>id;

if(id == "999")

{

break;

}

num++;

}

in_file3.close();

return num;

}

void open_html()

{

file_in2.open("data2.txt");

}

void open_wrote()

{

file_out.open("file.htm");

}

void close_html()

{

file_in2.close();

}

void close_wrote()

{

file_out.close();

}

void do_write()

{

int length_string=0;

string id; // id = id[0] + id[1]....id[n-1]

file_in.open("data.txt");

file_out.open("file.htm",ios::app);

char buffer[15000]; // set high to make sure no overflow

file_in>>id; // get the new ID from the file

length_string=id.length(); // get length of ID

char ch; // used for character holder

int x=0; // used to count how much of the buffer should be used

file_in2.get((ch));

cout<<ch<<endl;

do

{

buffer[x]=ch; // while the file_in.get(ch) has a char, assign it to the buffer

x++;

}while(file_in2.get(ch));

char new_id[15];

for(int w=0;w<15;w++)

{

new_id[w] = id[w];

}

for(int i=0;i<x;i++)

{

if(buffer == '@')

{

cout<<"Found an @"<<endl;

buffer=id[0];

buffer[i+1]=id[1];

buffer[i+2]=id[2];

buffer[i+3]=id[3];

buffer[i+4]=id[4];

buffer[i+5]=id[5];

buffer[i+6]=id[6];

buffer[i+7]=id[7];

buffer[i+8]=id[8];

buffer[i+9]=id[9];

buffer[i+10]=id[10];

buffer[i+11]=id[11];

buffer[i+12]=id[12];

buffer[i+13]=id[13];

buffer[i+14]=id[14];

i=i+15;

}

}

for(i=0;i<x;i++)

{

if(buffer == '@')

{

//do nothing

}

else

{

file_out<<buffer;//write the file

}

}

x=0;

}

Can someone help me out? Thanks !!!

Gnome

This article has been dead for over six months. Start a new discussion instead.