I don't know if this is correct because I'm new to C++. I tried it in
managed code. I have no idea how to do this in unmanaged code... But at
least I tried and it works. I didn't read it into structure, so I'll leave
that part to you.
#include "stdafx.h"
#using <mscorlib.dll>
using namespace System;
using namespace System::IO;
using namespace System::Text;
int _tmain()
{
String* strTextFilePath;
strTextFilePath = "D:\\Temp\\MyTextFile.txt";
FileStream* fs = new FileStream(strTextFilePath, FileMode::Open,
FileAccess::Read);
StreamReader* sr = new StreamReader(fs);
while(sr->Peek() != -1)
{
Console::WriteLine(sr->ReadLine());
};
Console::Read();
return 0;
}
adwoa said:
Can anyone help show me how to read records line by line from a text file
into structures. I know how to read the whole file but can't do line by
line.