For my OS class I’m supposed to implement Linux’s cat using only system calls (no printf)
Reading this reference I found it being used to print to a file. I guess I should manipulate ofstream.
In the example appears: ofstream outfile ("new.txt",ofstream::binary);
How can I make it write to the screen?
EDIT: I realized this write() is part of iostream library, is this the same as the int write (int fd, char *buf , int size) system call?
No,
std::ostream::writeis not the same as thewritesystem call. It does (almost certainly) use thewritesystem call, at least on a system like Linux that has such a thing, and it normally does pretty similar things, but it’s still a separate thing of its own.Linux will, however, pre-open standard input, standard output and standard error streams for your process. To write to the screen, you’d normally use
write(i.e., the one that is a system call) to write to stream number1or stream number2(which are standard output and standard error respectively).If you need to write to the screen even if those are re-directed, you’d normally open a stream to
/dev/ttyand (again) usewriteto write to it: