[an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive]
 
[an error occurred while processing this directive] [an error occurred while processing this directive]
Skåne Sjælland Linux User Group - http://www.sslug.dk Home   Subscribe   Mail Archive   Forum   Calendar   Search
MhonArc Date: [Date Prev] [Date Index] [Date Next]   Thread: [Date Prev] [Thread Index] [Date Next]   MhonArc
 

ifstream tilbage til start



Hej,

Jeg prøver at rode med et map og indlæsning fra en fil i C++
Jeg kunne godt tænke mig at læse min fil ind to gange, 
kan jeg det uden at åbne og lukke den to gange ?

Det her virker og læser filen ind i et map een gang.

#include <fstream>
#include <map>
#include <string>
int main(int argc, char *argv[])
{
  ifstream f("hallo");

  string s;
  map <string, int> counters;
  while (f >> s )
  {
    ++counters[s];

  }
  f.close();
  return 0;
}


Jeg ville gerne køre den samme while lykke en gang til.
Jeg har prøvet at indsætte dette lige efter while lykken

f.seekg (0, ios::beg);

og så køre while lykken en gang til, men det har ingen effekt.

   while (f >> s )
{
    ++counters[s];

}

Hvordan får jeg sat pointeren til starten af streamen igen ?
Mvh
Dennis





 
Home   Subscribe   Mail Archive   Index   Calendar   Search

 
 
Questions about the web-pages to <www_admin>. Last modified 2005-08-10, 20:09 CEST [an error occurred while processing this directive]
This page is maintained by [an error occurred while processing this directive]MHonArc [an error occurred while processing this directive] # [an error occurred while processing this directive] *