简体   繁体   中英

C++ Unrecognized escape sequence

I want to create a string that contains all possible special chars.

However, the compiler gives me the warning "Unrecognized escape sequence" in this line:

wstring s=L".,;*:-_⁊#‘⁂‡…–«»¤¤¡=„+-¶~´:№\¯/?‽!¡-¢–”¥—†¿»¤{}«[-]()·^°$§%&«|⸗<´>²³£­€™℗@©®~µ´`'" + wstring(1,34);

Can anybody please tell me which one of the characters I may not add to this string the way I did?

您必须将\\转义为\\\\ ,否则\\¯将被解释为(无效的)转义序列:

wstring s=L".,;*:-_⁊#‘⁂‡…–«»¤¤¡=„+-¶~´:№\\¯/?‽!¡-¢–”¥—†¿»¤{}«[-]()·^°$§%&«|⸗<´>²³£­€™℗@©®~µ´`'" + wstring(1,34);

Escape sequence is a character string that has a different meaning than the literal characters themselves. In C and C++ the sequence begins with \\ so if your string contains a double quote or backslash it must be escaped properly using \\" and \\\\

In long copy-pasted strings it may be difficult to spot those characters and it's also less maintainable in the future so it's recommended to use raw string literals with the prefix R so you don't need any escapes at all

wstring s = LR"(.,;*:-_⁊#‘⁂‡…–«»¤¤¡=„+-¶~´:№\¯/?‽!¡-¢–”¥—†¿»¤{}«[-]()·^°$§%&«|⸗<´>²³£­€™℗@©®~µ´`')"
          + wstring(1,34);

A special delimiter string may be inserted outside the parentheses like this LR"delim(special string)delim" in case your raw string contains a )" sequence

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM