I am writing a program that has some functions in it to open, read and then search through lines in a file. It will be a txt file.

Currently I am trying to find a way to pass the Open file to the ReadFileLine function, so that it can then go through the file, line by line, passing each line to a function which searches for specific words in this line. I hope you're following me?

The file is opened using the following code:
Stream^ mystream;
OpenFileDialog^ OpenFile = gcnew OpenFileDialog;
OpenFile->InitialDirectory = "c://";
OpenFile->Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*";
OpenFile->FilterIndex = 2;
OpenFile->RestoreDirectory = true;

if (OpenFile->ShowDialog() == ::StatsReading::DialogResult::OK)
if( (mystream = OpenFile->OpenFile()) != nullptr)

Now how do I get an event raised or a pointer to this open file that I can use in the function which will take a line from this file to do something with??

Please give me some example code if possible?

I am writing in Visual C++.net Express.

Thank you,

9 Years
Discussion Span
Last Post by Infarction

I'm not very familiar with the .NET libraries, but it looks like OpenFile returns a Stream, so whatever has the method ReadFileLine should take the stream and do whatever is involved in reading a line.

Btw, please use [code] and [/code] tags when you post code, it preserves indentation and doesnt insert smileys. Makes it easier for the rest of us to read your code :icon_wink:

This topic has been dead for over six months. 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.