📜  C++ fwide()

📅  最后修改于: 2020-09-25 09:30:45             🧑  作者: Mango

C++中的fwide() 函数尝试设置方向或查询给定文件流的当前方向。

fwide() 函数在头文件中定义。

fwide()原型

int fwide( FILE* stream, int mode );

根据mode的值,确定fwide 函数的作用。

fwide()参数

fwide()返回值

fwide() 函数返回:

示例:fwide() 函数如何工作?

#include 
#include 
#include 
using namespace std;

int main()
{
    FILE *fp;
    int retVal;

    fp = fopen("file.txt","r");
    retVal = fwide(fp,0);
    if (retVal == 0)
        cout << "Stream has no orientation" << endl;
    else if (retVal > 0)
        cout << "Stream is wide-oriented" << endl;
    else
        cout << "Stream is byte-oriented" << endl;

    /* wide oriented stream */
    cout << "Setting stream to wide-orientation" << endl;
    retVal = fwide(fp,1);
    if (retVal == 0)
        cout << "Stream has no orientation" << endl;
    else if (retVal > 0)
        cout << "Stream is wide-oriented" << endl;
    else
        cout << "Stream is byte-oriented" << endl;

    return 0;
}

运行该程序时,输出为:

Stream has no orientation
Setting stream to wide-orientation
Stream is wide-oriented