0

How can i read in data in different functions without losing the stream's place in the file. i.e function a and function b both open a data stream to read in first and last names from a file. however function b reads in the first name as well rather than the last name because it loses it's place as i closed the stream in function a and re-opened the stream in function b. would passing an open stream to other functions prevent this? if not i guess i'll doddle how to implement seekg and tellg

2
Contributors
1
Reply
2
Views
8 Years
Discussion Span
Last Post by Ancient Dragon
0

Pass the open stream to each function as a parameter.

void func1(ifstream& in)
{

}

void func2(ifstream& in)
{

}

int main()
{
   ifstream in("myfile.txt");
   funct1(in);
   funct2(in);

}
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.