Whats this Error mean?

W

Weasel

This occured right after i tryed to compile the file


hello.cpp:9:2: warning: no newline at end of file
 
T

Thomas Tutone

Weasel said:
This occured right after i tryed to compile the file


hello.cpp:9:2: warning: no newline at end of file

Uhhmmm... it means what it says. The last character of the file is
supposed to be a newline. Open the file. Go to the end. Hit <Enter>
(or whatever the equivalent is on your keyboard). Save the file.
Recompile. The warning should be gone.

By the way - it was a warning, not an error. It didn't stop you from
compiling the file, but making the above change will make the compiler
stop giving you that warning. But you should consult your compiler
documentation for more info.

Best regards,

Tom
 
D

Default User

Weasel said:
o ok ty ty ty sorry im just learning c++ :(

That's nice. Are you still learning how to use Google? I know I've
mentioned the quote thing to you before? Why are you not using it?


Brian
 
G

Greg Comeau

This occured right after i tryed to compile the file
hello.cpp:9:2: warning: no newline at end of file

Comeau, in strict mode, gives:

error: last line of file ends without a newline

In other modes it might just be a warning.
In C mode, the diagnostic can be removed.


As both these compilers are saying, source files should
end with a newline. The C++ Standard says in 2.1p2:
"If a source file that is not empty does not end in a new-line
character, or ends in a new-line character immediately
preceded by a backslash character, the behavior is undefined."
C99 5.1.1.2p2 reads:
"A source file that is not empty shall end in a new-line character,
which shall not be immediately preceded by a backslash character
before any such splicing takes place."

This normally occurs as a result of a text editor that does not
put out a trailing NL in a text file. It may also indicate that
somehow the rest of a file got tossed, though that would also
normally give some other errors if it got cut off so abruptly.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,012
Latest member
RoxanneDzm

Latest Threads

Top