- 论坛徽章:
- 0
|
代码如下:- int main ()
- {
- char buffer[1000];
- FILE *pFile1,
- int iFile2;
- pFile1=fopen ("myfile.txt","w");
- iFile2=open ("myfile2.txt",O_WRITE | O_SYNC);
- setbuf ( pFile1 , buffer );
- const char* strANSC = "This is sent to a buffered stream";
- fwrite(pFile1, strANSC, 1, strlen(strANSC));
- fflush (pFile1);
- const char* strPOSIX="This is sent to an unbuffered stream";
- write(iFile2, strPOSIX, strlen(strPOSIX));
- fclose (pFile1);
- close (iFile2);
- return 0;
- }
复制代码 在Linux运行时, 如果知道分别使用fwrite()/write调用系统内核写的次数 。write()是POSIX标准,不带
缓冲 的,每次的读写都要调用trap一次内核读写的系统调用。
[ 本帖最后由 SybaseLU 于 2007-7-10 09:59 编辑 ] |
|