让我有一个字符串:C++ 14名摘录引用的字符串逐字包括引号
string tstring = "Some arbitrarily long string which has \"double quotes\" which has to be printed verbatim";
我试图使用stringstreams并引述提取的话
stringstream stream(tstring);
string tepm;
while(stream >> std::quoted(temp))
cout << temp << endl;
但上面跳过引号引用的字符串
Some
arbitrarily
.
.
double quotes
.
.
verbatim
我想引用的字符串逐字打印,包含引号
Some
arbitrarily
.
.
"double quotes"
.
.
verbatim
我怎么做到这一点使用引用的函数,或者如果它是不可能有一个更好的办法做到这一点(当然从阅读逐个字符的分开,做所有的工作我自己)
编辑:
这里是MCVE的要求
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
using namespace std;
int main(){
string sspace = "Hi this is \"Real Madrid\"";
stringstream stream(sspace);
string fpart;
while(stream >> quoted(fpart)){
cout << fpart << endl;
}
return 0;
}
'std :: quoted'删除引号。见http://en.cppreference.com/w/cpp/io/manip/quoted。 “quoted”旨在将引用的子字符串视为单个项目,忽略空格。 –
@DavidLively我知道引用是删除引号,因此输出,有没有办法找出它是否被引用并保留引号和字符串? –
嗯..实际上,quoted'的定义似乎表示,当用于像'stream >> std :: quoted(temp)'这样的输入时,应该保留转义的引号。你可以发布一个完整的,可编译的*短*样本吗? –