简体   繁体   English

C ++ std :: string如何格式化带有多个双引号的String文字?

[英]C++ std::string how to format String literal with multiple double quotes?

I have a std::string literal with double quotes inside double quotes, inside double quotes. 我有一个std :: string文字,在双引号内,双引号内有双引号。 What format do I need to use to make it work? 我需要使用什么格式才能使其正常工作? Here is an example: 这是一个例子:

std:string http_command = "wget --post-data="user=bla password=bla query=select * from bla bla where username="" and name=bla\" http:://example.com"

The following part is failing username="" 以下部分失败了username=""

Thanks guys. 多谢你们。

Update: Fixed my sample, I had one extra double quote there. 更新:修正了我的示例,在那里我又加了一个双引号。

std::string http_command = "wget --post-data=\"user=bla password=bla query=\"select * from bla bla where username=\"\" and name=bla\" http:://example.com"

转义除第一个和最后一个(界定您的字符串的那些)之外的所有引号。

std:string http_command = "wget --post-data=\"user=bla password=bla query=\\\"select * from bla bla where username=\\\\\\"\\\\\\" and name=bla\\\" \" http:://example.com"

A bit of a guess, but I think that you have to escape the internal backslahes. 有点猜测,但是我认为您必须逃避内部的后退。 Note that I think you were missing a quote at the end of the post data. 请注意,我认为您在帖子数据末尾缺少引号。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 C ++:在C ++ std :: string中考虑双引号(“)的字面含义,而不使用反斜杠(\\) - C++: Consider the literal meaning of double quotes(") in a C++ std::string without using backslash (\) 带有双引号的字符串替换为带双引号的字符串 - c++ - Replace string with double quotes to a string with double quotes 在C ++中比较字符文字与Std :: String - Comparing Character Literal to Std::String in C++ 从 C++ 中的字符串中删除双引号 - remove double quotes from a string in c++ c ++传递字符串文字而不是const std :: string&? - c++ passing a string literal instead of a const std::string&? 如何将双引号放入字符串文字中? - How can I get double quotes into a string literal? c++:转换std::map<std::string, double> 到 std::map<std::string_view, double></std::string_view,></std::string,> - c++ : convert std::map<std::string, double> to std::map<std::string_view, double> 为什么 std::vector 的字符串文字初始化列表不能创建 std::vector<std::string> 在 C++ 中?</std::string> - Why can't a string literal initializer list for a std::vector create a std::vector<std::string> in C++? 格式字符串不是可变参数模板 function 中的字符串文字(C++) - format string is not a string literal in a variadic template function (C++) 如何有效地从 std::string 中删除双引号(如果存在) - How to efficiently remove double quotes from std::string if they exist
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM