“No newline at end of file” compiler warning

后端 未结 11 1003
逝去的感伤
逝去的感伤 2020-11-27 09:50

What is the reason for the following warning in some C++ compilers?

No newline at end of file

Why should I have an empty line at

11条回答
  •  悲&欢浪女
    2020-11-27 10:38

    It isn't referring to a blank line, it's whether the last line (which can have content in it) is terminated with a newline.

    Most text editors will put a newline at the end of the last line of a file, so if the last line doesn't have one, there is a risk that the file has been truncated. However, there are valid reasons why you might not want the newline so it is only a warning, not an error.

提交回复
热议问题