Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c++ > #83751

Re: getline() problem

From Manfred <noname@add.invalid>
Newsgroups comp.lang.c++
Subject Re: getline() problem
Date 2022-04-25 20:17 +0200
Organization Aioe.org NNTP Server
Message-ID <t46ojk$1nv4$1@gioia.aioe.org> (permalink)
References (4 earlier) <t41hkn$6p9$1@dont-email.me> <t45de2$1sln$2@gioia.aioe.org> <t46f86$or8$1@dont-email.me> <t46g6s$3e7$1@dont-email.me> <t46i9f$mnk$1@dont-email.me>

Show all headers | View raw


On 4/25/2022 6:29 PM, James Kuyper wrote:
> On 4/25/22 11:54, Vir Campestris wrote:
>> On 25/04/2022 16:37, James Kuyper wrote:
> ...
>>> The C++ standard says very little about the differences between text
>>> mode and binary mode, cross-referencing the C standard for such issues.
>>> The C standard says something important to this issue:
>>>
>>> "... Data read in from a text stream will necessarily compare equal to
>>> the data that were earlier written out to that stream only if: the data
>>> consist only of printing characters and the control characters
>>> horizontal tab and new-line; no new-line character is immediately
>>> preceded by space characters; and the last character is a new-line
>>> character. ..." (7.21.2p2).
>>>
>>> As a general rule, you should not write data to a text stream if it
>>> contains any feature invalidating that guarantee, and you should not
>>> read data from a text stream if it contains any of those things.
>>
>> Windows text files have 13,10 as a newline sequence, not just 10 as in
>> Linux etc.
>>
>> This dates back to at least CP/M where the byte stream in the file
>> exactly matched the one you would send to your CRT or printer, and a
>> line feed really did move the roller but not the print head.
>>
>> I have a vague feeling that Apple might use 10,13 - certainly I've met
>> it somewhere in the past.
>>
>> The point of text mode is to allow a program to ignore these differences
>> by allowing the runtime to handle them.
>>
>> It's not 100%.
> 
> Those requirements explicitly allow new-line characters be writable to
> text streams, and that when they are read in again, the result must
> compare equal to '\n'.  This means that on platforms where a new-line is
> represented in the underlying file by "\n\r" or by "\r\n", then standard
> I/O routines must convert '\n' to that sequence on write, and convert
> that sequence back to '\n' when reading from the same stream.
> If the "not 100%' you're talking about violates that guarantee, then
> what you're talking about isn't a conforming implementation of C++.
> 
> 

MS-Windows (and DOS before that) behave as you describe ('\n' is stored 
as '\r\n' on disk and converted back to '\n' upon read) - or, more 
properly, the MS C runtime does that.
So, according to your quote above from the C standard that allows for 
only LF and TAB for round trip consistency of text files, MS 
implementations have been standard compliant since the beginning of time.
That said, interoperability when dealing with text streams between 
Windows and other systems is still painful.

Back to comp.lang.c++ | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

getline() problem Jivanmukta <jivanmukta@poczta.onet.pl> - 2022-04-23 19:07 +0200
  Re: getline() problem Andrey Tarasevich <andreytarasevich@hotmail.com> - 2022-04-23 10:17 -0700
    Re: getline() problem Jivanmukta <jivanmukta@poczta.onet.pl> - 2022-04-23 19:40 +0200
      Re: getline() problem Jivanmukta <jivanmukta@poczta.onet.pl> - 2022-04-23 19:59 +0200
        Re: getline() problem Paavo Helde <eesnimi@osa.pri.ee> - 2022-04-23 21:47 +0300
          Re: getline() problem Juha Nieminen <nospam@thanks.invalid> - 2022-04-25 06:00 +0000
            Re: getline() problem Öö Tiib <ootiib@hot.ee> - 2022-04-25 00:12 -0700
            Re: getline() problem Paavo Helde <eesnimi@osa.pri.ee> - 2022-04-25 11:40 +0300
            Re: getline() problem James Kuyper <jameskuyper@alumni.caltech.edu> - 2022-04-25 11:37 -0400
              Re: getline() problem Vir Campestris <vir.campestris@invalid.invalid> - 2022-04-25 16:54 +0100
                Re: getline() problem James Kuyper <jameskuyper@alumni.caltech.edu> - 2022-04-25 12:29 -0400
                Re: getline() problem scott@slp53.sl.home (Scott Lurndal) - 2022-04-25 17:29 +0000
                Re: getline() problem Manfred <noname@add.invalid> - 2022-04-25 20:17 +0200
                Re: getline() problem Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2022-04-25 10:19 -0700
                Re: getline() problem Andrey Tarasevich <andreytarasevich@hotmail.com> - 2022-04-25 10:41 -0700
                Re: getline() problem Paavo Helde <eesnimi@osa.pri.ee> - 2022-04-25 21:58 +0300
              Re: getline() problem scott@slp53.sl.home (Scott Lurndal) - 2022-04-25 15:56 +0000
                Re: getline() problem James Kuyper <jameskuyper@alumni.caltech.edu> - 2022-04-25 13:12 -0400
                Re: getline() problem Andrey Tarasevich <andreytarasevich@hotmail.com> - 2022-04-25 11:03 -0700
                Re: getline() problem scott@slp53.sl.home (Scott Lurndal) - 2022-04-25 19:05 +0000
                Re: getline() problem Andrey Tarasevich <andreytarasevich@hotmail.com> - 2022-04-25 12:48 -0700
                Re: getline() problem Ben <ben.usenet@bsb.me.uk> - 2022-04-25 21:46 +0100
                Re: getline() problem Juha Nieminen <nospam@thanks.invalid> - 2022-04-26 05:43 +0000
                Re: getline() problem David Brown <david.brown@hesbynett.no> - 2022-04-26 09:36 +0200
                Re: getline() problem Juha Nieminen <nospam@thanks.invalid> - 2022-04-26 09:18 +0000
                Re: getline() problem Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2022-04-26 02:47 -0700
                Re: getline() problem Juha Nieminen <nospam@thanks.invalid> - 2022-04-26 11:06 +0000
                Re: getline() problem David Brown <david.brown@hesbynett.no> - 2022-04-26 15:52 +0200
                Re: getline() problem Andrey Tarasevich <andreytarasevich@hotmail.com> - 2022-04-26 07:04 -0700
                Re: getline() problem Manfred <noname@add.invalid> - 2022-04-26 16:49 +0200
                Re: getline() problem James Kuyper <jameskuyper@alumni.caltech.edu> - 2022-04-26 12:01 -0400
                Re: getline() problem James Kuyper <jameskuyper@alumni.caltech.edu> - 2022-04-26 11:49 -0400
                Re: getline() problem Manfred <noname@add.invalid> - 2022-04-25 20:23 +0200
            Re: getline() problem Andrey Tarasevich <andreytarasevich@hotmail.com> - 2022-04-25 10:33 -0700
              Re: getline() problem "james...@alumni.caltech.edu" <jameskuyper@alumni.caltech.edu> - 2022-04-25 10:52 -0700
                Re: getline() problem Andrey Tarasevich <andreytarasevich@hotmail.com> - 2022-04-25 11:08 -0700
                Re: getline() problem "james...@alumni.caltech.edu" <jameskuyper@alumni.caltech.edu> - 2022-04-25 21:18 -0700
                Re: getline() problem Andrey Tarasevich <andreytarasevich@hotmail.com> - 2022-04-25 22:04 -0700
              Re: getline() problem Paavo Helde <eesnimi@osa.pri.ee> - 2022-04-25 22:06 +0300
                Re: getline() problem Andrey Tarasevich <andreytarasevich@hotmail.com> - 2022-04-25 13:02 -0700
        Re: getline() problem Barry Schwarz <schwarzb@delq.com> - 2022-04-23 12:54 -0700
        Re: getline() problem Montmorency <none@none.com> - 2022-04-23 14:45 -0700
          Re: getline() problem Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2022-04-23 16:49 -0700
            Re: getline() problem Ben <ben.usenet@bsb.me.uk> - 2022-04-24 01:04 +0100
              Re: getline() problem Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2022-04-23 18:24 -0700
                Re: getline() problem Ben <ben.usenet@bsb.me.uk> - 2022-04-24 03:16 +0100
                Re: getline() problem Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2022-04-24 22:51 -0700
                Re: getline() problem Ben <ben.usenet@bsb.me.uk> - 2022-04-25 11:07 +0100
            Re: getline() problem Andrey Tarasevich <andreytarasevich@hotmail.com> - 2022-04-23 17:15 -0700
              Re: getline() problem Andrey Tarasevich <andreytarasevich@hotmail.com> - 2022-04-23 18:23 -0700
          Re: getline() problem Jivanmukta <jivanmukta@poczta.onet.pl> - 2022-04-24 05:28 +0200
  Re: getline() problem Jivanmukta <jivanmukta@poczta.onet.pl> - 2022-04-25 12:41 +0200
    Re: getline() problem Paavo Helde <eesnimi@osa.pri.ee> - 2022-04-25 14:33 +0300
    Re: getline() problem Jivanmukta <jivanmukta@poczta.onet.pl> - 2022-04-25 18:53 +0200
      Re: getline() problem Paavo Helde <eesnimi@osa.pri.ee> - 2022-04-25 22:08 +0300
        Re: getline() problem Jivanmukta <jivanmukta@poczta.onet.pl> - 2022-04-26 09:01 +0200
          Re: getline() problem Paavo Helde <eesnimi@osa.pri.ee> - 2022-04-26 11:15 +0300

csiph-web