Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 question
Index -> Programming, C++ -> C++ Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Geminias




PostPosted: Fri Sep 23, 2005 5:12 pm   Post subject: question

compiler: mingw

when i compile this source code i get a "warning: no newline at end of file"

the prog still works, but i got this warning and was wondering what it means exactly.

code:
#include <iostream>
using namespace std;

int division (int x, int z=2)
{
        int r;
        r= x/z;
        return (r);
}
int main ()
{
        std::cout<< division (10)<<std::endl;
        std::cout<< "division using both arguments"<<division (20,5);
        return 0;
}
Sponsor
Sponsor
Sponsor
sponsor
Mazer




PostPosted: Fri Sep 23, 2005 5:46 pm   Post subject: (No subject)

Why do you declare that you're using the standard namespace and then go ahead and use "std::" in front of cout? I'm no compiler-error expert, but maybe is't just some crazy problem because of that? (at the very least the code might make a bit more sense).
[Gandalf]




PostPosted: Fri Sep 23, 2005 5:50 pm   Post subject: (No subject)

Works fine for me.

You should always indent, use proper whitespace, the point of "using namespace std" is so that you don't need to use std::, and your function could be written better as:

code:
int division (int x, int z = 2)
{
    return (x/z);
}
1of42




PostPosted: Fri Sep 23, 2005 5:51 pm   Post subject: (No subject)

It means what it says. There is no newline at the end of the file. Put one there, and it will compile without warnings.
Geminias




PostPosted: Fri Sep 23, 2005 6:50 pm   Post subject: (No subject)

lol.. i didn't really know what "use namespace std;" really did, i was just having trouble compiling and i saw this other program that had that so i decided i would just copy it in there LOL.

good to know anyways!

(ps. i do indent and organize my code neatly but when i copied/paste it messed it up)

you say include a newline at the end, like what do you mean just type "newline" at the end lol?
rizzix




PostPosted: Fri Sep 23, 2005 6:53 pm   Post subject: (No subject)

yes you do.. just that you used [quote] instead of [code] or [syntax="cpp"]
wtd




PostPosted: Fri Sep 23, 2005 6:54 pm   Post subject: (No subject)

C and C++ are meant to work on many different hardware platforms, running many different operating systems. Many of these operating systems don't consider a text file properly formatted unless it ends in a newline.

This is why GCC (G++ is part of GCC) warns about the lack of a newline.
rizzix




PostPosted: Fri Sep 23, 2005 8:06 pm   Post subject: (No subject)

wtd wrote:
Many of these operating systems don't consider a text file properly formatted unless it ends in a newline..
huh?
Sponsor
Sponsor
Sponsor
sponsor
wtd




PostPosted: Fri Sep 23, 2005 8:09 pm   Post subject: (No subject)

I believe that VMS is such a system. The IO system gets all confused if plain text files don't end in a newline.
rizzix




PostPosted: Fri Sep 23, 2005 8:11 pm   Post subject: (No subject)

oh. weird.
Monstrosity_




PostPosted: Fri Sep 30, 2005 4:06 pm   Post subject: Re: question

Geminias wrote:

when i compile this source code i get a "warning: no newline at end of file" the prog still works, but i got this warning and was wondering what it means exactly.

I dont use much c++, I use c instead. But I do know they have some of the same "rules" in the standards. Somewhere in section 2 should state that having no newline or having a newline preceded by a backslash character at the end of your source file results in undefined behaviour.
Display posts from previous:   
   Index -> Programming, C++ -> C++ Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 11 Posts ]
Jump to:   


Style:  
Search: