首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

std::quoted

Defined in header <iomanip>

?

?

template< class CharT > /*unspecified*/ quoted(const CharT* s, CharT delim=CharT('"'), CharT escape=CharT('\'));

(1)

(since C++14)

template< class CharT, class Traits, class Allocator > /*unspecified*/ quoted(const std::basic_string<CharT, Traits, Allocator>& s, CharT delim=CharT('"'), CharT escape=CharT('\'));

(2)

(since C++14)

template< class CharT, class Traits> /*unspecified*/ quoted(std::basic_string_view<CharT, Traits> s, CharT delim=CharT('"'), CharT escape=CharT('\'));

(3)

(since C++17)

template< class CharT, class Traits, class Allocator > /*unspecified*/ quoted(std::basic_string<CharT, Traits, Allocator>& s, CharT delim=CharT('"'), CharT escape=CharT('\'));

(4)

(since C++14)

允许插入和提取引用的字符串,例如在CSV或XML中找到的字符串。

1-3%29在表达式中使用时out << quoted(s, delim, escape),在哪里out的输出流。char_type等于CharT对于过载2,traits_type等于Traits,表现为FormattedOutputFunction,插入out一系列字符seq结构如下:

A%29首先,字符delim被添加到序列中。

B%29然后每个字符s,除非要输出的下一个字符等于delim或等于escape%28 As由流%27s确定traits_type::eq%29,然后首先附加一个额外的副本escape

最后C%29,delim附加到seq再来一次,如果seq.size() < out.width(),补充out.width()-seq.size()填充字符的副本out.fill()在序列%28if的末尾ios_base::left设为out.flags()%29或在序列%28的开头,在所有其他情况下%29。最后,输出结果序列中的每个字符,就像通过调用out.rdbuf()->sputn(seq, n),在哪里n=std::max(out.width(), seq.size())out.width(0)取消…的影响std::setw如果有的话。

4%29在表达式中使用时in >> quoted(s, delim, escape),在哪里in的输入流。char_type等于CharTtraits_type等于Traits,从in,使用std::basic_istream::operator>>,根据下列规则:

如果提取的第一个字符不相等,则为%29delim%28 As由流%27s确定traits_type::eq%29,然后简单地执行in >> s...

如果第一个字符是分隔符%29,则为B%29,否则为%28:

1%29关闭skipws输入流上的标志

2%29通过调用s.clear()

3%29提取字符in并将它们附加到s,但每当escape提取字符,忽略该字符,并将下一个字符追加到s.当提取停止时!in==true或者当一个未逃脱的人delim人物被发现了。

4%29丢弃最后%28未转义%29delim性格。

5%29恢复skipws将输入流标记为其原始值。

参数

s

-

the string to insert or extract

delim

-

the character to use as the delimiter, defaults to "

escape

-

the character to use as the escape character, defaults to \

返回值

返回未指定类型的对象,以便所描述的行为发生。

例外

抛出std::ios_base::failure如果operator>>operator<<扔。

二次

代码语言:javascript
复制
#include <iostream>
#include <iomanip>
#include <sstream>
 
int main()
{
    std::stringstream ss;
    std::string in = "String with spaces, and embedded \"quotes\" too";
    std::string out;
 
    ss << std::quoted(in);
    std::cout << "read in     [" << in << "]\n"
              << "stored as   [" << ss.str() << "]\n";
 
    ss >> std::quoted(out);
    std::cout << "written out [" << out << "]\n";
}

二次

产出:

二次

代码语言:javascript
复制
read in     [String with spaces, and embedded "quotes" too]
stored as   ["String with spaces, and embedded \"quotes\" too"]
written out [String with spaces, and embedded "quotes" too]

二次

另见

代码语言:txt
复制
 ? cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com