Why do I get a "warning: no newline at end of file" ?
Posted
by user198729
on Stack Overflow
See other posts from Stack Overflow
or by user198729
Published on 2010-03-28T08:29:42Z
Indexed on
2010/03/28
8:33 UTC
Read the original article
Hit count: 254
The file is a helloworld.cpp:
#include <iostream>
using namespace std;
int main() {
if(true)
cout << "!!!Hello World!!!" << endl; // prints !!!Hello World!!!
return 0;
}
But when I build it,get a warning:
g++ -Wall -O2 -c -o hw.o hw.cpp
hw.cpp:8:2: warning: no newline at end of file
g++ -o myprog hw.o
If I add a newline at the end,the warning will go.
Why is that newline at end of file recommended in a cpp source file?
© Stack Overflow or respective owner