|
|
|
#1 |
|
Messages: n/a
Hébergeur: |
i write two codes:
printf("123\r"); printf("123\n"); the lattar. as we all know. the output will be: 123 press any key to continue but the formmer will be: press any key to continue which means data:123 has lost. Y? |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
YarvinG Liu said:
> i write two codes: > printf("123\r"); > printf("123\n"); > the lattar. as we all know. the output will be: > 123 > press any key to continue > > but the formmer will be: > press any key to continue > > which means data:123 has lost. Right. > Y? I don't understand. If you mean "Why?", however, the answer is that writing a '\r' character to the standard output stream moves the active position to the initial position of the current line. It would seem that your IDE then writes "press any key to continue" to the standard output stream, starting at that position, and therefore overwriting your "123" text. -- Richard Heathfield <http://www.cpax.org.uk> Email: -http://www. +rjh@ Google users: <http://www.cpax.org.uk/prg/writings/googly.php> "Usenet is a strange place" - dmr 29 July 1999 |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
"YarvinG Liu" <yarving@gmail.com> wrote in message news:be73985c-a476-44a2-b1b0-51d01458e6b0@h1g2000prh.googlegroups.com... >i write two codes: > printf("123\r"); > printf("123\n"); > the lattar. as we all know. the output will be: > 123 > press any key to continue > > but the formmer will be: > press any key to continue > > which means data:123 has lost. > Y? \r move the cursor back to the start of the line, the "press any key.." is then written over the top of 123. Its probably safest to always go \r\n if you are on windows systems. |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
Dan said:
<snip> > \r move the cursor back to the start of the line, the "press any key.." > is then written over the top of 123. Its probably safest to always go > \r\n if you are on windows systems. No, that's pointless - \n is perfectly adequate on *all* systems, including Windows. The stdout stream is a text stream. Like all text streams, if you write a '\n' to it, any necessary conversions *will* be done by the implementation. -- Richard Heathfield <http://www.cpax.org.uk> Email: -http://www. +rjh@ Google users: <http://www.cpax.org.uk/prg/writings/googly.php> "Usenet is a strange place" - dmr 29 July 1999 |
|
![]() |
| Outils de la discussion | |
|
|