I have an assignment where I need to make a utility where if ran, it would perform the same action as a tee command in linux.
So the tee command takes the command line:
ls *.txt | tee txtfiles.txt
But for my assignment if I named the utility to be "test" then the command line would run:
ls *.txt | test txtfiles.txt
I am making this utility in C++ and need to use GNU Tools (so autoconf, automake, ./configure, etc) to compile the utility. I have no clue how to code the tee command in c++ as my background is VERY MINIMAL. One friend suggested I try this code:
#include <fstream>
int main( int argc, const char** argv )
{
std::ofstream file(argv[1]);
teestream teeout(std::cout, file);
teeout << std::cin.rdbuf();
}
I tried running ./configure and then make but a number of errors pop up when I run make:
gcc -DPACKAGE=\"test\" -DVERSION=\"1.0\" -I. -I. -g -O2 -c test.c
test.c:1:19: error: fstream: No such file or directory
test.c: In function ‘main’:
test.c:5: error: expected expression before ‘:’ token
test.c:6: error: ‘teestream’ undeclared (first use in this function)
test.c:6: error: (Each undeclared identifier is reported only once
test.c:6: error: for each function it appears in.)
test.c:6: error: expected ‘;’ before ‘teeout’
test.c:7: error: ‘teeout’ undeclared (first use in this function)
test.c:7: error: ‘std’ undeclared (first use in this function)
test.c:7: error: expected ‘;’ before ‘:’ token
make: *** [test.o] Error 1
Help? :(