new line character is considered as two characters

S

Someonekicked

if you create a new file , open it and only hit enter then save. if you use
seekg(0,ios::end) and then tellg(), tellg() will return 2 (not 1); so new
line character is considered as two characters.

Is there a possible way so new line character can be considered (reading and
writing) as one character ? I need that in my program and the new line
character being two characters is messing up everything.
 
O

osmium

Someonekicked said:
if you create a new file , open it and only hit enter then save. if you
use seekg(0,ios::end) and then tellg(), tellg() will return 2 (not 1); so
new line character is considered as two characters.

Is there a possible way so new line character can be considered (reading
and writing) as one character ? I need that in my program and the new line
character being two characters is messing up everything.

In a non-Unix system, new line is usually silently stored as two characters,
CR and LF. When these characters are retrieved, they are *silently*
converted to one character again. In a binary file none of these
conversions occur. The word "binary" was a poor choice to describe this
phenomena.

I can't tell exactly what you are trying to do but investigate this area.

If you think of "binary" as meaning "strict ASCII" it may help get your arms
around this thing.
 
K

Karl Heinz Buchegger

Someonekicked said:
if you create a new file , open it and only hit enter then save. if you use
seekg(0,ios::end) and then tellg(), tellg() will return 2 (not 1); so new
line character is considered as two characters.

Is there a possible way so new line character can be considered (reading and
writing) as one character ? I need that in my program and the new line
character being two characters is messing up everything.

You want to open the file in binary mode.
 
S

sirclif

i think you want to recheck your assumption. if you create a file, hit
return TWICE, and run your program, you get 3, not 4.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,189
Latest member
CryptoTaxSoftware

Latest Threads

Top