How to copy text file in C or C++?

后端 未结 6 676
走了就别回头了
走了就别回头了 2020-12-11 06:00

When trying to copy a text file A to another file B, there may have several methods: 1) byte by byte 2) word by word 3) line by line

which one is more efficient?

6条回答
  •  情深已故
    2020-12-11 06:45

    If done well, Byte by byte is more efficient. Of course that's not the whole story: it depends on how many bytes you copy at once. If you literally copy byte for byte you'll do an I/O call for every byte and end up being slower than the string libraries. Most people just guess at a good buffer size (generally 2048 or bigger, in multiples of 2) and use that.

提交回复
热议问题