std:: quoted
|
헤더 파일에 정의됨
<iomanip>
|
||
|
template
<
class
CharT
>
/*unspecified*/
quoted
(
const
CharT
*
s,
|
(1) | (C++14부터) |
|
template
<
class
CharT,
class
Traits,
class
Allocator
>
/*unspecified*/
quoted
(
const
std::
basic_string
<
CharT, Traits, Allocator
>
&
s,
|
(2) | (C++14부터) |
|
template
<
class
CharT,
class
Traits
>
/*unspecified*/
quoted
(
std::
basic_string_view
<
CharT, Traits
>
s,
|
(3) | (C++17부터) |
|
template
<
class
CharT,
class
Traits,
class
Allocator
>
/*unspecified*/
quoted
(
std::
basic_string
<
CharT, Traits, Allocator
>
&
s,
|
(4) | (C++14부터) |
CSV나 XML에서 볼 수 있는 따옴표로 묶인 문자열의 삽입 및 추출을 허용합니다.
out
은
char_type
이
CharT
와 같은 출력 스트림이고, (2,3) 오버로드의 경우
traits_type
이
Traits
와 같으면,
FormattedOutputFunction
으로 동작하며,
out
에 다음과 같이 구성된 문자 시퀀스
seq
를 삽입합니다:
seq
에 한 번 더 추가됩니다.
- 그런 다음, seq. size ( ) < out. width ( ) 인 경우, out. width ( ) - seq. size ( ) 개의 채움 문자 out. fill ( ) 를 시퀀스의 끝에 추가합니다( ios_base :: left 가 out. flags ( ) 에 설정된 경우) 또는 시퀀스의 시작 부분에 추가합니다(다른 모든 경우).
- 마지막으로, 결과 시퀀스의 각 문자를 다음 호출과 동일하게 출력합니다: out. rdbuf ( ) - > sputn ( seq, n ) , 여기서 n = std:: max ( out. width ( ) , seq. size ( ) ) 이며, out. width ( 0 ) 을 통해 std::setw 의 효과가 있을 경우 이를 취소합니다.
in
은
char_type
이
CharT
와 같고
traits_type
이
Traits
와 같은 입력 스트림인 경우, 다음 규칙에 따라
in
으로부터 문자를 추출합니다:
traits_type::eq
에 의해 결정됨), 단순히
in
>>
s
를 수행합니다.
in
에서 연속적인 문자들을 추출하여
s
에 추가합니다. 단,
escape
문자가 추출될 때마다 이를 무시하고 다음 문자를
s
에 추가합니다. 추출은
!
in
==
true
가 되거나 이스케이프 처리되지 않은
delim
문자를 찾을 때 중단됩니다.
목차 |
매개변수
| s | - | 삽입하거나 추출할 문자열 |
| delim | - | 구분자로 사용할 문자, 기본값은 " |
| escape | - | 이스케이프 문자로 사용할 문자, 기본값은 \ |
반환값
설명된 동작이 일어나도록 지정되지 않은 타입의 객체를 반환합니다.
예외
std::ios_base::failure 를 던집니다. 단, operator >> 또는 operator << 가 예외를 던지는 경우에 한합니다.
참고 사항
| Feature-test 매크로 | 값 | 표준 | 기능 |
|---|---|---|---|
__cpp_lib_quoted_string_io
|
201304L
|
(C++14) |
std::quoted
|
예제
#include <iomanip> #include <iostream> #include <sstream> void default_delimiter() { const std::string in = "std::quoted() quotes this string and embedded \"quotes\" too"; std::stringstream ss; ss << std::quoted(in); std::string out; ss >> std::quoted(out); std::cout << "Default delimiter case:\n" "read in [" << in << "]\n" "stored as [" << ss.str() << "]\n" "written out [" << out << "]\n\n"; } void custom_delimiter() { const char delim{'$'}; const char escape{'%'}; const std::string in = "std::quoted() quotes this string and embedded $quotes$ $too"; std::stringstream ss; ss << std::quoted(in, delim, escape); std::string out; ss >> std::quoted(out, delim, escape); std::cout << "Custom delimiter case:\n" "read in [" << in << "]\n" "stored as [" << ss.str() << "]\n" "written out [" << out << "]\n\n"; } int main() { default_delimiter(); custom_delimiter(); }
출력:
Default delimiter case: read in [std::quoted() quotes this string and embedded "quotes" too] stored as ["std::quoted() quotes this string and embedded \"quotes\" too"] written out [std::quoted() quotes this string and embedded "quotes" too] Custom delimiter case: read in [std::quoted() quotes this string and embedded $quotes$ $too] stored as [$std::quoted() quotes this string and embedded %$quotes%$ %$too$] written out [std::quoted() quotes this string and embedded $quotes$ $too]
참고 항목
|
(C++20)
|
인수의 형식화된 표현을 새 문자열에 저장합니다
(함수 템플릿) |