Supplement to the C ++ function getline

Disclaimer: This article is a blogger original article, shall not be reproduced without the bloggers allowed. https://blog.csdn.net/qiuchangyong/article/details/88970777

C ++ implementation reads a line from the stream is getline function, which is defined in the <string> file, there are four overloads. I found that the actual use of a difference in behavior under Windows and Linux. Let me talk about here, wrap text files under Windows is '\ r' '\ n' two characters, line breaks under Linux is '\ n', line breaks under the Mac is '\ r'.

When using getline read a row under Windows, you can get rid of the tail '\ r' and '\ n'. However, the use when reading a line, only to get rid of the tail of the getline '\ n' in Linux, with particular attention to if there is '\ r', is really stubborn, which is handling. I have not tested the behavior of the getline function under Mac, here ignored.

Achieve reads a line from the file fgets C language is a function to be noted that, in the read line string '\ r' '\ n' is not removed. This behavior of the C ++ function getline not the same.

Guess you like

Origin blog.csdn.net/qiuchangyong/article/details/88970777