tellg() and seekg()????

I have a text file which has a size of 18 bytes.
The text file contains
1
2
3
ABCDEFG
HIJ
KLMN


I was wondering why it has 18 bytes instead of 17?
I tried to create a program that will show the Integer value of each characters, and it shows that there are two new line characters (Int: 10, '\n')

Just like this.
1
2
3
4
5
6
7
8
A  B  C  D  E  F  G  \n  \n
0  1  2  3  4  5  6  7   8

H  I    J   \n   \n
9  10  11  12    13

K    L     M    N  [EOF]
14   15   16   17   18


Why there are two new line characters?? O_o
Last edited on
Are you sure both the characters at the end are \n? Some systems like windows use \r\n to mark a new line.
My OS is Win7 and I'm using MVS 2010 Pro
Yes.. when I convert it to it's decimal value it shows 10.. position number 7,8,12,and 13

If it's \r\n it should display 13 and 10 on position 7,8,12 and 13
\r is carriage return right?

or maybe you're right It just shows that there are two \n but it's really \r\n?
Last edited on
Does the program that prints the integer value of each character open the file in binary mode? I don't think tellg() and seekg() works very well in text mode, if that's what you're using.
Last edited on
It just shows that there are two \n but it's really \r\n?
Yes, switch to binary in order to get the correct positions. See:

http://cplusplus.com/reference/iostream/fstream/fstream/
so i tried to open it in binary mode, and it display 13 and 10 on position 7,8,12 and 13
So it's really \r\n... Why does it only work well in binary mode?
tellg() shows the real position, but in text mode the line endings are converted to a single \n if necessary (like on windows systems)
Topic archived. No new replies allowed.