Hi,

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,
T-Fizz

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:

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.