if i wanna use open, read in a c++ style program, how could I do
Hello,
I am trying to make it run, but it looks like that the usage is not correct. How could I get it. Because I also want the program running in Linux.
Code:
#include <iostream>
// For open()
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
int main(void)
{
int fd;
char * buf = NULL;
const char pathname[] = "\\\\.\\pipe\\com_1";
std::cout<<pathname<<std::endl;
fd = open(pathname, O_CREAT | O_RDWR);
if(fd == 0)
std::cout<<" open pipe failure"<<std::endl;
else
{
while(1)
{
read(fd, buf, sizeof(char));
std::cout<<*buf;
}
}
close(fd);
return 0;
}