I am trying to read in user input which is a file path (riddled with escape characters) into a CString. How can I do this without asking the user to replace '\' with '\\'?

For instance:

CString myString;
	myString = _T("c:\test\file\j\mypath\path\user.bin");
	wcout << myString.GetBuffer(myString.GetLength()) << endl;

outputs:

c: estQilejmypathpathuser .bin

The only time \\ is needed is for string literals, like one you posted because the compiler has to interpret each of the characters in the string literal. When the path is typed in from the keyboard of read from a file the \ does not have to be escaped because the compiler will never see it. So typing the path in an edit control then coping it to a CString object can be done without escape characters.

Comments
I see, thank you

Ancient D. is correct. Try running this program, noticing the output when you type path and filename.

#include <iostream>
#include <string>

int main()
{
	std::string mystring;

	std::cout << "Enter path and filename->";
	std::cin >> mystring;

	for (int i = 0; i < mystring.size(); ++i)
		std::cout << mystring[i] << " ";

	std::cout << std::endl;
	return 0;
}
Comments
thank you for the example!
This question has already been answered. Start a new discussion instead.