1. I am using MS Visual C++ 6.0. What compiler am I using?
Thanks for your reply : )
If u are using Microsoftt VC++ then the compiler is microsoft compiler which can be called from command prompt using command cl.
Other famous compilers are gcc,g++ etc...
No, '\n' is a universally accepted escape character to print a newline. I just think that how '\n' and endl are implemented varies from compiler to compiler.
‘\n’ refers to a newline. A newline is actually OS specific. This is where it gets a bit confusing. People will refer to the \n and \r characters independently (Windows is \r\n , *NIX is \n, and old Macs are \r ). But in C++, ‘\n’ is a portable equivalent to whatever the OS considers a newline.
endl is a manipulator function. It does two things effectively. It first inserts a newline into the stream. If the stream is buffered, it will flush it. Which is why if all you want is a newline, insert a ‘\n’. I realize endl is ubiquitously used by beginners because that is what books use. But endl is a function. ‘\n’ is a character.
= and == has already been discussed.
Lotus, your compiler is VC++ 6. It’s old. Get something newer than that. You can get the following for free: gcc for Windows (known as MinGW), Visual C++ 2005 Express Edition. I’m not entirely sure about the VS 2008 betas. Whatever the case, your old compiler will limit you in learning advanced C++. Although it’s perfectly fine for plain C.
EDIT: So I should clarify here. '\n' and endl are not a compiler issue. They are very firmly defined by the standard. endl is defined to insert a newline and then flush the buffer. Period.
'\n' is OS/platform specific. If a compiler supports a platform, it supports the right newline conversion for that platform.
you will end with with an endless loop as a=b will always evaluate to being true (unless for some reason the assignment failed.
No you will end with an endless loop unless then value of b happens to be 0. The expression a=b assigns b to a and returns the new value of a. If b is 0 then 0 is assigned to a and 0 is returned.
In C++ the exception to this is exceptions, if a and/or b are objects and in evaluating the object and assignment an exception is raise the loop will also stop.
'\n' is OS/platform specific. If a compiler supports a platform, it supports the right newline conversion for that platform.
I thought this was only true for a stream/file opened in text mode.
For a stream/file opened in binary mode no conversation is done the code writes exactly what it is given so '/n' is written as byte value of 10 (assuming an ASCII execution character set).
Comment