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

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

本文关键字:文字 字符串 string std 格式化 C++      更新时间:2023-10-16

我有一个 std::string 文字,双引号内有双引号,双引号内有双引号。我需要使用什么格式才能使其工作?下面是一个示例:

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

以下部分username=""失败

谢谢大家。

更新:修复了我的示例,我在那里有一个额外的双引号。

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"

有点猜测,但我认为你必须摆脱内部的反击。请注意,我认为您在帖子数据的末尾缺少引用。