Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game. |
| Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
01-24-2005, 08:31 PM
|
#1
|
|
Senior Member
Registered: Jul 2003
Location: So. Cal.
Distribution: Slack 11
Posts: 1,737
Rep:
|
No new line at end of file? What does this mean?
I am messing around with cpp and I typed up this simple code:
// first C++ program
#include <iostream.h>
int main ()
{
cout <<" Hello World!";
return 0;
}
Then I do cpp test.cpp
and lots of stuff flies by on the screen and I get the error: test.cpp:9:2: warning: no newline at end of file.
should I be using something else other than cpp progname.cpp?
Is there a way to do away with this errror?
I am using cpp version 3.3.4
Thanks.
Last edited by BajaNick; 01-24-2005 at 08:35 PM.
|
|
|
|
01-24-2005, 08:45 PM
|
#2
|
|
Member
Registered: Jul 2003
Location: CT, USA
Distribution: Debian Sarge (server), Etch (work/home)
Posts: 601
Rep:
|
> and I get the error: test.cpp:9:2: warning: no newline at end of file.
That's not an error. It's just a warning.
Open the file in an editor, go to the last line of the file, and hit enter to add a blank line to the end of the file. :)
Though, besides that, you should be using #include <iostream> instead of <iostream.h>. Then put in a "using std::cout;" after it.
Last edited by johnMG; 01-24-2005 at 08:48 PM.
|
|
|
|
01-24-2005, 08:57 PM
|
#3
|
|
Senior Member
Registered: Jul 2003
Location: So. Cal.
Distribution: Slack 11
Posts: 1,737
Original Poster
Rep:
|
That did it, Thanks alot. 
I think some of the online tutorials might be kinda outdated.
Last edited by BajaNick; 01-24-2005 at 09:00 PM.
|
|
|
|
01-24-2005, 10:04 PM
|
#4
|
|
Guru
Registered: Nov 2003
Location: N. E. England
Distribution: Fedora, CentOS, Debian
Posts: 16,298
Rep:
|
Yeah, I ended up buying a c++ book coz most of the stuff on the web is outdated.
|
|
|
|
01-24-2005, 11:06 PM
|
#5
|
|
LQ Newbie
Registered: Dec 2004
Location: Wisconsin, USA
Distribution: Debian
Posts: 3
Rep:
|
Just out of curiosity, what's the point of having the extra newline at the end of the file? gcc on OS X doesn't give this warning.
|
|
|
|
01-25-2005, 01:58 AM
|
#6
|
|
Moderator
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris10, Solaris 11, Ubuntu, OL
Posts: 9,311
|
It's not an extra new-line, each line should be terminated by an "end of line" tag, and this is \n under unix.
On MacOS, this used to be \r, perhaps the reason why gcc is more tolerant on newer releases of this O/S.
|
|
|
|
02-07-2005, 03:23 PM
|
#7
|
|
Member
Registered: Aug 2004
Distribution: Mandrake 10.2(Mandriva), SuSE 9.3, Slackware 9.1, Xandros 3.1, Knoppix 3.9, FreeBSD 5.3, RedHat9
Posts: 122
Rep:
|
do you know real reason of that?
|
|
|
|
02-07-2005, 03:37 PM
|
#8
|
|
Member
Registered: Jul 2003
Location: CT, USA
Distribution: Debian Sarge (server), Etch (work/home)
Posts: 601
Rep:
|
There's probably still some ancient compilers out there (maybe even very old versions of GCC?) that want each line to end with a newline or else they crash. My guess is that GCC is just trying to help you make your code compatible with these dino's.
|
|
|
|
02-07-2005, 06:30 PM
|
#9
|
|
Senior Member
Registered: Jan 2004
Location: Oregon, USA
Distribution: Slackware
Posts: 1,246
Rep:
|
Actually, gcc warns about it because it has to according to the standard. Check out this link for a brief description: http://gcc.gnu.org/ml/gcc/2003-11/msg01568.html
If you have a compiler that doesn't warn you about the lack of a newline character then that compiler doesn't meet the standards. Burn the disc it came on and get a real compiler.
|
|
|
|
05-04-2013, 07:20 PM
|
#10
|
|
LQ Newbie
Registered: May 2013
Posts: 1
Rep: 
|
Great!
|
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 09:27 AM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|