Funkce fwide () v C ++ se buď pokusí nastavit orientaci, nebo se dotazuje na aktuální orientaci daného proudu souboru.
Funkce fwide () je definována v hlavičkovém souboru.
široký () prototyp
int fwide (FILE * stream, int režim);
Na základě hodnoty režimu se rozhodne, co dělá široká funkce.
- Pokud
mode> 0
se tato funkce pokusí učinit stream široce orientovaný. - Pokud
mode < 0
se tato funkce pokusí provést stream bajtově orientovaný. - Pokud
mode == 0
tato funkce dotazuje pouze aktuální orientaci streamu. - Pokud o orientaci streamu již bylo rozhodnuto provedením výstupu nebo dřívějším voláním fwide, tato funkce nic neudělá.
fwide () parametry
- stream: Ukazatel na stream souboru pro nastavení nebo dotaz na orientaci.
- mode: Celočíselná hodnota, která určuje, zda se má nastavit nebo dotazovat na orientaci streamu.
fwide () Vrátit hodnotu
Funkce fwide () vrací:
- Kladné celé číslo, pokud je stream široko orientovaný.
- Záporné celé číslo, pokud je stream orientován na bajty.
- Nula, pokud stream nemá žádnou orientaci.
Příklad: Jak funguje funkce 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" < 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" < 0) cout << "Stream is wide-oriented" << endl; else cout << "Stream is byte-oriented" << endl; return 0; )
Když spustíte program, výstup bude:
Stream nemá žádnou orientaci Nastavení proudu na širokou orientaci Stream je široko orientovaný