Re: [Dev-C++] Newbie Q " /n " or " endl" ?
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Graham D. <g.d...@nt...> - 2003-08-04 08:51:19
|
To just add a small amount to Abhijit's reply, think of it like this: '\n' (note: _not_ '/n') is just a character, but endl is a function that can do all sorts of things in addition to just adding a character or two to the output stream. Abhijit Shylanath wrote: >Hello, Graham. > > > >>My book defines "/n" as new line. >>And defines " endl " as end line. >>But gives me no clue as to what the difference is or when to use which. >>can anyone explain the difference to me ? >> >> > >Two differences you should know: > > '\n' is new-line to C, and to Unix, but may not be new-line to your OS. >For example, for Windows, "\r\n" is new-line. IIRC, for macs, it's just >'\r'. endl takes care of these platform specific thingies for you (as a >matter of fact, so does '\n' in files opened in text mode in STDIO, but endl >is a more graceful and conformant solution. > > Next, endl makes sure that the text that you've written is flushed. Most >streams have a buffer, so that when you write to them, the connected device >or file is not updated instantly, but the results are stored in memory (this >is for reasons of speed). endl makes sure that they (the files or devices) >are updated. > > If in doubt, use endl. If you're working with raw data (binary files or >such), then you will have to use '\n'. When you start working with binary >files, you should be able to tell the difference anyway, if your book is any >good. > >Hope this helps. > >-- >Abhijit Shylanath >Homepage: http://mudeth.tripod.com/ > > > > >------------------------------------------------------- >This SF.Net email sponsored by: Free pre-built ASP.NET sites including >Data Reports, E-commerce, Portals, and Forums are available now. >Download today and enter to win an XBOX or Visual Studio .NET. >http://aspnet.click-url.com/go/psa00100003ave/direct;at.aspnet_072303_01/01 >_______________________________________________ >Dev-cpp-users mailing list >Dev...@li... >TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm >https://lists.sourceforge.net/lists/listinfo/dev-cpp-users > > > |