Hall-D Software  alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
fd_write.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 
11 using namespace std;
12 using namespace xstream;
13 
14 
15 int main(int argc, char* argv[]){
16 
17  try{
18  int fd;
19  if(2==argc){
20  fd = open(argv[1], O_WRONLY|O_CREAT);
21  if(-1==fd){
22  perror("open");
23  return errno;
24  }else{
25  fd::streambuf fs(fd,true);
26  ostream os(&fs);
27  os.exceptions(ios::badbit);
28 
29  os<<cin.rdbuf();
30  }
31  }else{
32  cerr<<argv[0]<<" file"<<endl;
33  }
34  }
35  catch(exception& e){
36  cerr<<"Error: "<<e.what()<<endl;
37  }
38 
39  return 0;
40 }
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