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

后端 未结 6 669
走了就别回头了
走了就别回头了 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:47

    If you do word-by-word or line-by line you can hardly reconstruct the original file since the are many forms of line breaks (\r, \n, \r\n) and spaces (\p, \f, 0x32) embedded in text files which you are risking to loose this way.

    The most efficient way to copy files is to use byte-buffers. The larger the buffer, the more efficient the copying will be, as long as your buffer size isn't bigger than hard disk internal buffer size (today mostly ~8mb).

提交回复
热议问题