Re: Problem with input streams
Faz_at_nowhere.com
Date: 11/09/03
- Next message: Nils: "static classvariable"
- Previous message: Faz_at_nowhere.com: "Re: compile hello world"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sun, 9 Nov 2003 16:26:25 -0000
Justin wrote in message news:vpquig4r92bld9@corp.supernews.com...
[]
> int main()
> {
> ifstream fin("text.txt");
> doStuff(fin); //processes the data from text.txt
> fin.close();
> fin.open("text2.txt");
> doStuff(fin); //processes the data from text2.txt
> return 0;
> }
>
[]
> not. Are there flags that I have to change or something to reset fin? I
> thought all I had to do was close the old file and open a new one. Any
help
> would be great on this matter. Also... along the same lines. What do I
I'm no guru on streams so won't give you an elegant answer. But to just
make your code 'work' you could try using nested blocks to 'refresh' fin
each time you use it, thus:
int main()
{
{
ifstream fin("text.txt");
doStuff(fin);
}
{
ifstream fin("text2.txt"); // or s/text2/text
doStuff(fin); // or s/Stuff/OtherStuff
}
}
On second thought, the approach actually has a certain elegance
because now you're treating each file EXACTLY the same. It can also
solve your second problem (see comments).
Hope that helps,
Fazl
> int main()
> {
> ifstream fin("text.txt");
> doStuff(fin); //processes the data from text.txt
>
> //WHAT DO I PUT HERE
>
> doOtherStuff(fin); //processes the data from text.txt in a different
way
> return 0;
> }
[]
- Next message: Nils: "static classvariable"
- Previous message: Faz_at_nowhere.com: "Re: compile hello world"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|