std:: fwide
| I/O manipulators | ||||
| Print functions (C++23) | ||||
| C-style I/O | ||||
| Buffers | ||||
|
(C++23)
|
||||
|
(
C++98/26*
)
|
||||
|
(C++20)
|
||||
| Streams | ||||
| Abstractions | ||||
| File I/O | ||||
| String I/O | ||||
| Array I/O | ||||
|
(C++23)
|
||||
|
(C++23)
|
||||
|
(C++23)
|
||||
|
(
C++98/26*
)
|
||||
|
(
C++98/26*
)
|
||||
|
(
C++98/26*
)
|
||||
| Synchronized Output | ||||
|
(C++20)
|
||||
| Types | ||||
| Error category interface | ||||
|
(C++11)
|
||||
|
(C++11)
|
| Types and objects | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Functions | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Défini dans l'en-tête
<cwchar>
|
||
|
int
fwide
(
std::
FILE
*
stream,
int
mode
)
;
|
||
Si mode > 0 , tente de rendre le stream orienté large. Si mode < 0 , tente de rendre le stream orienté octet. Si mode == 0 , ne fait que consulter l'orientation actuelle du flux.
Si l'orientation du flux a déjà été décidée (en exécutant une sortie ou par un appel antérieur à fwide), cette fonction ne fait rien.
Table des matières |
Paramètres
| stream | - | pointeur vers le flux d'E/S C à modifier ou interroger |
| mode | - | valeur entière supérieure à zéro pour définir le flux en mode large, inférieure à zéro pour définir le flux en mode étroit, ou zéro pour interrogation uniquement |
Valeur de retour
Un entier supérieur à zéro si le flux est orienté large après cet appel, inférieur à zéro si le flux est orienté octet après cet appel, et zéro si le flux n'a pas d'orientation.
Exemple
Le code suivant définit et réinitialise l'orientation du flux.
#include <cstdio> #include <cstdlib> #include <cwchar> #include <iostream> void show_orientation(int n) { n < 0 ? std::wcout << "\tnarrow orientation\n" : n > 0 ? std::wcout << "\twide orientation\n" : std::wcout << "\tno orientation\n"; } void try_read(FILE* fp) { if (const int c = std::fgetc(fp); c == EOF) std::wcout << "\tnarrow character read failed\n"; else std::wcout << "\tnarrow character read '" << static_cast<char>(c) << "'\n"; if (const wint_t wc = std::fgetwc(fp); wc == WEOF) std::wcout << "\twide character read failed\n"; else std::wcout << "\twide character read '" << static_cast<wchar_t>(wc) << "'\n"; } int main() { enum fwide_orientation : int { narrow = -1, query, wide }; FILE* fp = std::fopen("main.cpp", "r"); if (!fp) { std::wcerr << "fopen() failed\n"; return EXIT_FAILURE; } std::wcout << "1) A newly opened stream has no orientation.\n"; show_orientation(std::fwide(fp, fwide_orientation::query)); std::wcout << "2) Establish byte orientation.\n"; show_orientation(std::fwide(fp, fwide_orientation::narrow)); try_read(fp); std::wcout << "3) Only freopen() can reset stream orientation.\n"; if (std::freopen("main.cpp", "r", fp) == NULL) { std::wcerr << "freopen() failed\n"; return EXIT_FAILURE; } std::wcout << "4) A reopened stream has no orientation.\n"; show_orientation(std::fwide(fp, fwide_orientation::query)); std::wcout << "5) Establish wide orientation.\n"; show_orientation(std::fwide(fp, fwide_orientation::wide)); try_read(fp); std::fclose(fp); }
Sortie possible :
1) A newly opened stream has no orientation.
no orientation
2) Establish byte orientation.
narrow orientation
narrow character read '#'
wide character read failed
3) Only freopen() can reset stream orientation.
4) A reopened stream has no orientation.
no orientation
5) Establish wide orientation.
wide orientation
narrow character read failed
wide character read '#'
Voir aussi
|
ouvre un fichier
(fonction) |
|
|
Documentation C
pour
fwide
|
|