How do you reset StreamReader? There is no seek function.
-
Hi. I'm using Visual Studio 2005 C++/CLI. I have a file that has its contents read into an array, one line of the file per element of the array. There may be 10 elements to read or 10,000 elements to read. I would like to define the array size dynamically by reading each line of the file, counting until all the lines are read. Then I want to go back to the begining of the stream but there is no Seek() function. I tried streamReader->Close() and then another streamReader = gcnew StramReader(fileStream) but that doesn't work. Can I reset the streamReader back to the beginning? Thanks Buck
-
Hi. I'm using Visual Studio 2005 C++/CLI. I have a file that has its contents read into an array, one line of the file per element of the array. There may be 10 elements to read or 10,000 elements to read. I would like to define the array size dynamically by reading each line of the file, counting until all the lines are read. Then I want to go back to the begining of the stream but there is no Seek() function. I tried streamReader->Close() and then another streamReader = gcnew StramReader(fileStream) but that doesn't work. Can I reset the streamReader back to the beginning? Thanks Buck
I think you can access the Seek method through the StreamReader's BaseStream property. I'm not by a C++ compiler so I can't test this. Try this out:
FileStream* fs = new FileStream(S"YourFile.txt", FileMode::???, FileAccess::???);
StreamReader* sr = new StreamReader(fs);sr->BaseStream->Seek(0, SeekOrigin::Begin);
I think you will also need to call
sr->DiscardBufferedData()
after the Seek or you will get unexpected results. -
I think you can access the Seek method through the StreamReader's BaseStream property. I'm not by a C++ compiler so I can't test this. Try this out:
FileStream* fs = new FileStream(S"YourFile.txt", FileMode::???, FileAccess::???);
StreamReader* sr = new StreamReader(fs);sr->BaseStream->Seek(0, SeekOrigin::Begin);
I think you will also need to call
sr->DiscardBufferedData()
after the Seek or you will get unexpected results.