Is there a way to use verbatim String literals in managed C++? Similar to C#'s
String Docs = @"c:\documents and settings\"
A verbatim string literal consists of an @ character followed by a double-quote character, zero or more characters, and a closing double-quote character. A simple example is @"hello".
In C#, a verbatim string is created using a special symbol @. @ is known as a verbatim identifier. If a string contains @ as a prefix followed by double quotes, then compiler identifies that string as a verbatim string and compile that string.
In C the type of a string literal is a char[]. In C++, an ordinary string literal has type 'array of n const char'. For example, The type of the string literal "Hello" is "array of 6 const char". It can, however, be converted to a const char* by array-to-pointer conversion.
in C++11, there is raw string literal:
cout<<R"((\"ddd\aa)\n)"<<endl;
cout<<R"delimiter((\"ddd\aa)\n)delimiter"<<endl;
output is:
(\"ddd\aa)\n
(\"ddd\aa)\n
This is not currently possible. Managed C++ string literals have almost the exact same rules as normal C++ strings. The managed C++ spec is in fact just an augmentation of the ANSI C++ standard.
Currently there is no support for C# style literal syntax in C++ (managed or not). You must manually escape every character.
See Section 9.1.3.3 in the C++/CLI spec for more details. (Spec Link)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With