operator<<,>> (std::basic_string)
|
헤더에 정의됨
<string>
|
||
|
template
<
class
CharT,
class
Traits,
class
Allocator
>
std::
basic_ostream
<
CharT, Traits
>
&
|
(1) | |
|
template
<
class
CharT,
class
Traits,
class
Allocator
>
std::
basic_istream
<
CharT, Traits
>
&
|
(2) | |
그런 다음 결과 시퀀스 seq ( str 의 내용에 패딩을 추가한 것)의 각 문자를 출력 스트림 os 에 삽입합니다. 이는 마치 os. rdbuf ( ) - > sputn ( seq, n ) 을 호출하는 것과 같으며, 여기서 n 은 std:: max ( os. width ( ) , str. size ( ) ) 입니다. 마지막으로, os. width ( 0 ) 을 호출하여 std::setw 의 효과가 있다면 취소합니다.
|
다음 코드와 동일합니다: return os << std:: basic_string_view < CharT, Traits > ( str ) ; . |
(C++17부터) |
-
N개의 문자를 읽었을 때, 여기서N은 is. width ( ) 이 is. width ( ) > 0 인 경우 그 값, 그렇지 않으면 str. max_size ( ) 입니다. - 스트림 is 에서 파일 끝(EOF) 조건이 발생한 경우, 또는
- std:: isspace ( c, is. getloc ( ) ) 가 true 인 경우( is 의 다음 문자 c 에 대해, 이 공백 문자는 입력 스트림에 남아 있습니다).
어떤 문자도 추출되지 않으면 std::ios::failbit 가 is 에 설정되며, 이는 std::ios_base::failure 를 발생시킬 수 있습니다.
마지막으로, is. width ( 0 ) 를 호출하여 std::setw 의 효과를 취소합니다(있는 경우).
목차 |
예외
매개변수
| os | - | 문자 출력 스트림 |
| is | - | 문자 입력 스트림 |
| str | - | 삽입되거나 추출될 문자열 |
반환값
예제
#include <iostream> #include <sstream> #include <string> int main() { std::string greeting = "Hello, whirled!"; std::istringstream iss(greeting); std::string hello_comma, whirled, word; iss >> hello_comma; iss >> whirled; std::cout << greeting << '\n' << hello_comma << '\n' << whirled << '\n'; // Reset the stream iss.clear(); iss.seekg(0); while (iss >> word) std::cout << '+' << word << '\n'; }
출력:
Hello, whirled! Hello, whirled! +Hello, +whirled!
결함 보고서
다음의 동작 변경 결함 보고서들은 이전에 발표된 C++ 표준에 소급 적용되었습니다.
| DR | 적용 대상 | 게시된 동작 | 올바른 동작 |
|---|---|---|---|
| LWG 25 | C++98 | n 이 os. width ( ) 와 str. size ( ) 중 더 작은 값이었음 | n 이 둘 중 더 큰 값임 |
| LWG 90 | C++98 |
std::
isspace
(
c, getloc
(
)
)
로 공백을 확인했으나,
getloc
이
<string>
에 선언되지 않음
|
getloc
(
)
를
is. getloc ( ) 로 대체함 |
| LWG 91 | C++98 |
operator>>
가
FormattedInputFunction 으로 동작하지 않음 |
FormattedInputFunction 으로 동작함 |
| LWG 211 | C++98 |
operator>>
가 문자를 추출하지 않을 때
failbit
를 설정하지 않음
|
failbit
를 설정함
|
| LWG 435 | C++98 |
문자가
os.
rdbuf
(
)
-
>
sputn
(
str.
data
(
)
, n
)
로 삽입되었고,
LWG issue 25 의 해결로 인해 os. width ( ) 가 str. size ( ) 보다 클 때 동작이 정의되지 않음 |
패딩을 먼저 결정하고
패딩된 문자 시퀀스를 대신 삽입함 |
| LWG 586 | C++98 |
operator<<
가
FormattedOutputFunction 으로 동작하지 않음 |
FormattedOutputFunction 으로 동작함 |
참고 항목
|
(C++17)
|
string view에 대한 스트림 출력을 수행합니다
(함수 템플릿) |