#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)同一文件,使用的多个流,各个流的定向设置互不影响。