If I'm reading a text file line by line, how do I get the byte address of the start of each line?
Printable View
If I'm reading a text file line by line, how do I get the byte address of the start of each line?
That depends, how are you reading the lines in? I'm assuming you're using C++, so if you have a string or CString, you can just use &variableName.
I'm using string class.
ifstream file;
name = 'text.txt';
file.open(name.data());
while(getline(file, lnstr))
{
cout << file.seekg();
}
This is what I was doing, but it keeps spitting out the same number. I want to spit it out line by line what the address is. On another note I'm trying to show it as byte values, specifically in 8bytes.
1) use tellg() not seekg()
2) care should be taken when using seekg/tellg using VC++ if the file is opened
in text mode.
3) it is still not clear to me why you need that information
In using MFC, see How to read a text file line by line.
What do you mean by "address", the offset from the start of the file? Just count the length of each line, making sure to account for the new line characters.
What do you mean by 8byte?