Re: [Dev-C++] How to work with *.txt files??
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: hielke_prins <hie...@he...> - 2004-09-18 17:57:18
|
>> How do I refer to each line of my *.txt file???
=20
/*
If you don't have any clue how to read a simple textfile, the first=20
thing you
proably have to do is buying a good book on C(++). But here ya go.
=20
I usually read small plaintext files in a vector using a simple=20
wrapperclass.
Something like this (if you meant to write it in C++ at least),=20
didn't test it:
*/
=20
Class Lines
{
string *d_line;
unsigned d_nLines;
=20
public:
Lines(istream streamIn);
/*
(of course you need some simple memberfunctions
returning linecount and lines on a given index too)
*/
}
=20
Lines::Lines(istream streamIn)
:
d_nLines(0)
{
string inputLine,
*tempLine;
=20
while(getline(streamIn, inputLine))
{
d_nLines++;
tempLine =3D new string[d_nLines];
for(unsigned i =3D 0; i < d_nLines; i++)
{
tempLine[i] =3D d_line[i];
}
delete d_line;
d_line =3D tempLine; =20
}
}
=20
Regards,
Hielke
|