我可以在stderr中使用CFPropertyListWriteToStream吗?

时间:2011-10-05 10:55:01

标签: c++ stream core-foundation

我想使用CFPropertyListWriteToStream写信给stderr。如果我输入stderr作为参数,我会收到错误:

error: cannot convert ‘FILE*’ to ‘__CFWriteStream*’ for argument ‘2’ to ‘CFIndex CFPropertyListWriteToStream

如何创建一个写入CFWriteStream的{​​{1}}对象?

1 个答案:

答案 0 :(得分:1)

你可以使用我找到的技术here

  CFWriteStreamRef stdoutStream = NULL;
  if (verbose) {
    CFURLRef devStdout =
      CFURLCreateWithFileSystemPath(NULL, CFSTR("/dev/stderr"),
                    kCFURLPOSIXPathStyle, false);
    stdoutStream = CFWriteStreamCreateWithFile(NULL, devStdout);
    if (stdoutStream == NULL)
      errexit("cannot create CFWriteStream for /dev/stderr");
    if (!CFWriteStreamOpen(stdoutStream))
      errexit("cannot open CFWriteStream for /dev/stderr");
  }