Re: Problem with input streams

Faz_at_nowhere.com
Date: 11/09/03


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;
> }
[]



Relevant Pages

  • Re: Unsigned integers
    ... >> less efficient (albeit more elegant, of course) than "unrolled loops' ... And I'm with you that small data doesn't always, or even usually, mean fast code. ... Using a short int to save space is going to cost you some speed when the native word size is a long int. ...
    (microsoft.public.vb.syntax)
  • Re: strange pointer behavior
    ... the thing that may cause problems, when you dereference element you will end ... up with an integer array, so you may be causing problems with that. ... will read more than it should because its expecting an int* and not an int. ... For the second problem, its because the parameter is being passed by value ...
    (microsoft.public.dotnet.languages.vc)
  • Re: segmentation error
    ... int ps; ... Here is your second problem, which you have managed to obscure with a ... for calloc, so it will make a default assumption (as the Standard ... Also note that you allocated space for twelve (n is ...
    (comp.lang.c)
  • Re: Batch sent X10 command
    ... another possible approach for a 5 second delay: ... A far more elegant approach for a delay is to use the "sleep" command ... It may be "elegant" but it doesn't actually work within the scope of what ... INT 21 ...
    (comp.home.automation)
  • Re: Passing an array of struct to function
    ... arnuld said: ... I am getting Segfaults and weired values. ... is there any elegant way ... int main ...
    (comp.lang.c)