What would be the most painless way to input un-escaped characters sequence to std::string
?
Instead of
std::string st = "C:\\program files\\myFile.txt";
something like: (Doesn't work correctly due to escape characters).
std::string st = "C:\program files\myFile.txt";
Using “r/R” Adding “r” or “R” to the target string triggers a repr() to the string internally and stops from the resolution of escape characters.
Your string would look like this: string str[]={"| | / / ||", "| |/ / ||", "| | ( \\ \\ \\ \\`_."}; In C++ (and most other C-based langauges), \ is used to indicate an escape character (e.g. \r , \n , \t , etc). If you want to have an actual "\" character in your string, you must escape it: \\ .
The std::string class manages the underlying storage for you, storing your strings in a contiguous manner. You can get access to this underlying buffer using the c_str() member function, which will return a pointer to null-terminated char array. This allows std::string to interoperate with C-string APIs.
You can do it with C++11 raw string literals:
std::string st = R"(C:\program files\myFile.txt)";
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