std:: fgetws
From cppreference.net
C++
Input/output library
| 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)
|
C-style I/O
| Types and objects | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Functions | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
헤더 파일에 정의됨
<cwchar>
|
||
|
wchar_t
*
fgetws
(
wchar_t
*
str,
int
count,
std::
FILE
*
stream
)
;
|
||
주어진 파일 스트림에서 최대 count - 1 개의 와이드 문자를 읽어 str 에 저장합니다. 생성된 와이드 문자열은 항상 null로 종료됩니다. 파일 끝에 도달하거나 개행 와이드 문자가 발견되면 구문 분석이 중단되며, 이 경우 str 에는 해당 와이드 개행 문자가 포함됩니다.
목차 |
매개변수
| str | - | 문자를 읽어올 와이드 문자열 |
| count | - | str 의 길이 |
| stream | - | 데이터를 읽어올 파일 스트림 |
반환값
str 성공 시, 오류 발생 시 널 포인터.
예제
이 코드 실행
#include <array> #include <clocale> #include <cstdio> #include <cstdlib> #include <cwchar> #include <cwctype> #include <iomanip> #include <iostream> #include <span> #include <string> void dump(std::span<const wchar_t> sp, std::size_t width = 14) { for (wchar_t wc : sp) std::wcout << (std::iswprint(wc) ? wc : L'.'); std::wcout << std::wstring(width > sp.size() ? width - sp.size() : 1, L' ') << std::hex << std::uppercase << std::setfill(L'0'); for (wchar_t wc : sp) std::wcout << std::setw(sizeof wc) << static_cast<unsigned>(wc) << ' '; std::wcout << '\n'; } int main() { // 와이드 문자를 포함하는 임시 파일 생성 std::setlocale(LC_ALL, "en_US.utf8"); std::FILE* tmpf = std::tmpfile(); for (const wchar_t* text : { L"Tétraèdre" L"\n", L"Cube" L"\n", L"Octaèdre" L"\n", L"Icosaèdre" L"\n", L"Dodécaèdre" L"\n" }) if (int rc = std::fputws(text, tmpf); rc == EOF) { std::perror("fputws()"); // POSIX는 errno가 설정되도록 요구함 return EXIT_FAILURE; } std::rewind(tmpf); std::array<wchar_t, 12> buf; while (std::fgetws(buf.data(), buf.size(), tmpf) != nullptr) dump(std::span(buf.data(), buf.size())); return EXIT_SUCCESS; }
가능한 출력:
Tétraèdre... 0054 00E9 0074 0072 0061 00E8 0064 0072 0065 000A 0000 0000 Cube..dre... 0043 0075 0062 0065 000A 0000 0064 0072 0065 000A 0000 0000 Octaèdre.... 004F 0063 0074 0061 00E8 0064 0072 0065 000A 0000 0000 0000 Icosaèdre... 0049 0063 006F 0073 0061 00E8 0064 0072 0065 000A 0000 0000 Dodécaèdre.. 0044 006F 0064 00E9 0063 0061 00E8 0064 0072 0065 000A 0000
참고 항목
|
표준 입력, 파일 스트림 또는 버퍼로부터 서식이 지정된 와이드 문자 입력을 읽음
(함수) |
|
|
파일 스트림에서 와이드 문자 하나를 가져옴
(함수) |
|
|
파일 스트림에 와이드 문자열을 씀
(함수) |
|
|
C 문서
for
fgetws
|
|