RE: [Dev-C++] Newbie Q " /n " or " endl" ?
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Abhijit S. <mu...@gm...> - 2003-08-03 18:18:47
|
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/ |