Correct way of using fdopen
问题 I mean to associate a file descriptor with a file pointer and use that for writing. I put together program io.cc below: int main() { ssize_t nbytes; const int fd = 3; char c[100] = "Testing\n"; nbytes = write(fd, (void *) c, strlen(c)); // Line #1 FILE * fp = fdopen(fd, "a"); fprintf(fp, "Writing to file descriptor %d\n", fd); cout << "Testing alternate writing to stdout and to another fd" << endl; fprintf(fp, "Writing again to file descriptor %d\n", fd); close(fd); // Line #2 return 0; } I