Hi there!
On Mon, 11 Jan 1999, James wrote:
> On Tue, 12 Jan 1999 [EMAIL PROTECTED] wrote:
>
> # I'm new to C and Linux. I notice that Turbo C has a 'cout' and 'cin'
> # command. What i sthe equivalent that I can use in Linux's C?
Glynn's right, these are C++, not C...
There's no reason you can't use these under Linux though, if you have the
C++ libraries and such installed (you most likely do)
As long as you stick to standard C++ and don't use Borland specific stuff
you should be all right...
Compile like this:
[tty5 3:52pm] cow:~/c#> cat >> test.C
#include <iostream.h>
int main(void)
{
cout << "Linux is ultra cool, I say.\n\n";
}
[tty5 3:54pm] cow:~/c#> g++ test.C
[tty5 3:55pm] cow:~/c#> ./a.out
Linux is ultra cool, I say.
[tty5 3:55pm] cow:~/c#>
Of course you'll want to use a better editor than cat, most likely :)
The UNIX convention for naming C++ files is to end them in .C or .cc, by
the way, but DOS's .cpp convention works fine too...
The equivalents for cout and cin in C, as James said, are printf() and
scanf(), indeed..,
> they're C++ functions, so either program in c++ or use printf and
> scanf like everyone else does :)
Nod. But they aren't exactly functions; they're actually streams, a type
of C++ object thing...
What you're doing when you use cout and cin is calling a member function
for the overloaded operators >> and <<
So you do call a C++ function, but I don't think cout and cin are
functions themselves; they're C++ objects (classes) I suspect.
> (i think cout and cin do exist in C, some book said they were what printf
> and scanf actually use...)
Uh, I don't know where you heard this, but I suspect it is falsery...
cin and cout aren't in any way part of ANSI C, and printf() and scanf()
are implemented in libc using system calls (or standard I/O calls which
call system calls), aren't they?
Anyway, have a rather nice day!!
Hope this is somewhat interesting to somebody :)
-Brett