Hall-D Software  alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
fd_read.cpp
Go to the documentation of this file.
1 #include <xstream/fd.h>
2 
3 #include <sys/types.h>
4 #include <sys/stat.h>
5 #include <fcntl.h>
6 #include <stdio.h>
7 #include <errno.h>
8 
9 #include <iostream>
10 #include <string>
11 
12 using namespace std;
13 using namespace xstream;
14 
15 
16 int main(int argc, char* argv[]){
17 
18  try{
19  int fd;
20  if(2==argc){
21  fd = open(argv[1], O_RDONLY);
22  if(-1==fd){
23  perror("open");
24  return errno;
25  }else{
26 
27  string line;
28 
29  fd::streambuf fs(fd,true);
30  istream is(&fs);
31  is.exceptions(ios::badbit);
32 
33  while(is.good()){
34  getline(is,line);
35  cout<<line<<endl;
36  }
37  }
38  }else{
39  cerr<<argv[0]<<" file"<<endl;
40  }
41  }
42  catch(exception& e){
43  cerr<<"Error: "<<e.what()<<endl;
44  }
45 
46  return 0;
47 }
textOut open("gains.txt")
TEllipse * e
C++ streambuf to work with file descriptors.
file descriptor streambuf
Definition: fd.h:33
int main(int argc, char *argv[])
Definition: gendoc.cc:6