wprintf()与printf()的冲突之原因: linux标准IO流定向

#include <stdio.h>
#include <errno.h>
#include <string.h>
// #include <locale.h>

int main()
{
    FILE *p = fopen("testStreamFile", "wb+");
    if(p == NULL)
    {
        printf("open file failed,errno=%d strerorr=%s\n", errno, strerror(errno));
        return -1;
    }
    fprintf(p, "hello\n");
    fwprintf(p, L"world\n");
    // fflush(p);

    // clear the stream's orientation and close the stream of testStreamFile,
    // then open the stream on file:testStreamFile.
    FILE *q = freopen("testStreamFile", "ab+", p);
    if(q == NULL)
    {
        printf("freopen file failed,errno=%d strerorr=%s\n", errno, strerror(errno));
        return -1;
    }

    printf("q=%p p=%p\n", q, p);

    // fwprintf call fwide to set stream's orientation as wide-orientation.
    fwprintf(q, L"123456[world]\n");
    fclose(q);

    return 0;
}

1)对于一个已定向的流,流的定向只能清除、不可修改。

      当然某些平台可能对IO流进行了扩展,使得一个已定向的流可进行修改。

      unix高级编程的第2版,p133~134对流的定向,有明确解释。

2)同一文件,使用的多个流,各个流的定向设置互不影响。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值