Quantcast
Channel: CodeSection,代码区,Linux操作系统:Ubuntu_Centos_Debian - CodeSec
Viewing all articles
Browse latest Browse all 11063

Newline at end of file

$
0
0

Many linux tools and compilers that process text files require the text file to end with a newline . This is simply because they are designed to process a series of lines, each ending with a newline. That means, the last line of the file should also end in a newline.

If the file does not end with a newline, then C++ compilers and other tools complain with errors such as No newline at end of file .

How do you end up with a file that does not end in newline? If you use tools that are written for other platforms like windows or are cross-platform, those might not follow the rule of ending the last line with a newline. The latest culprit who I found doing this mistake was the Visual Studio Code editor. Editors like Vim, which come from a Unix heritage, just do not allow you to save without a newline.

In Visual Studio Code, I set the files.insertFinalNewline option to true to fix this mistake.


Viewing all articles
Browse latest Browse all 11063

Trending Articles