Hi,
I'm let say stuck with some "legacy" code that i cannot make it to work
example:
Code:
struct noop {
void operator()(...) const {}
};
void Sweep (const string file){
int fd;
if(file.compare("stdin") == 0)
fd = STDIN_FILENO;
else
fd = open(&file[0], O_RDONLY);
char buf[BUFFER_SIZE + 1];
while(size_t bytes_read = read(fd, buf, BUFFER_SIZE)){
cout << buff;
// plus some additional complicated functions that i do not wish to reimplement
}
}
int main(int argc, char **argv){
string file = SetOptions(argc,argv); // function not shown
shared_ptr<istream> input;
int entries = 0, cnt =0;
char c, t;
// old code
if ( file.compare("-") == 0 || file.compare("") == 0 ){
Sweep("stdin");
}else{
Sweep(file);
}
// new code
if ( file.compare("-") == 0 || file.compare("") == 0 ){
input.reset(&cin, noop());
}else{
input.reset(new ifstream(file.c_str()));
}
entries = 18;
cout <<(char) (c=(*input).get()) << endl; // this prints a symbol i beliewe is eof if stdin is chosen.
while ((c=(*input).get())>0){
if (c == 'L' && t == '\n')
cnt++;
if(cnt > entries)
break;
cout << c;
t = c;
}
}
Actually it works if i specify the actual file but it does not if I try to cat file directly
Code:
./program -i file <- works
./program < file <- not
� is what i get
could anyone hint/provide a solution??
thnx