Skip to content

std::endl 描述有误 #47

Open
Open

Description

@Mq-b

endl 是一个典型的以讹传讹错误写法,只有当你的输出是指向另一个进程的管道时,其附带的刷新功能才有作用。

当输出是管道时,cout 需要 endl 才能刷新。
当输出是普通控制台时,cout 需要 endl 才能刷新。

我认为此处最后一句存在问题。普通控制台并不一定需要 endl 才能刷新。

endl 操纵符大多时候都是冗余的,"\n" 大多数时候也会进行刷新,即使是文件读写也很少会使用 endl 。

Activity

  1. archibate commented on Sep 24, 2024

    @archibate
    Contributor

    想说的应该是:

    当输出是管道时,cout 需要 endl 才能刷新。
    当输出是普通控制台时,cout 只需 '\n' 就能刷新,无需 endl。
    

    复制粘贴害的。

  2. archibate commented on Sep 24, 2024

    @archibate
    Contributor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions