I can use the Raw feature with strings to fix backslashes as backslashes and NOT escape sequences. But if I don't know the string at coding time (say I want the user to supply a string) and I use the name of the string, R"(name)" returns to me name. Is there a way to get the Raw functionality for strings which are input after the program is finished.
Huh? If the user enters a backslash then it gets written into the string as a backslash, period. No other interpretation is needed.
1 2 3 4 5 6 7 8 9 10
#include <iostream>
#include <string>
int main(){
std::string line;
std::getline(std::cin, line); //type in a backslash
if (line == "\\")
std::cout << "The input is a backslash!\n";
std::cout << line << std::endl;
}
hi helios;
What I have found is that a '\' written into a string is interpreted by c++ as an escape sequence \x where x is any alpha character. Raw changes that situation so that a backslash is just a backslash character. Then I hope to be able to change them into forward slashes, as Visual c++ complains when a directory string contains backslashes.
I am using CString as my input type, and I cannot get the CString Replace function to recognize either \ or \\ alone. \x works, but then it also changes every additional instance of x.
To JL Borges
Thanks, this looks like it has a chance of working. However, how do you get CStrings to print out their contents. On my system it prints the CString address!!
Help greatly appreciated. I am using Visual C++; is that the problem???
Thank you both very much. The final code looks a fair bit different in Microsoft Visual C++, but that is OK. I've just tested the adjusted code and it works very smoothly. Thanks again.