如果我得到一个路径LPCTSTR path="c:\temp\a.txt";在输出时'\'是无法正确输出的,得转成c:\\temp\\a.txt才行,怎么才能实现这个转换?

解决方案 »

  1.   

    一个一个的转,如果调用系统函数一般都会得到"dir\\path\\filename",不需要转
      

  2.   

    CString::Replace
    int Replace( TCHAR chOld, TCHAR chNew );int Replace( LPCTSTR lpszOld, LPCTSTR lpszNew );
    Example//First example, with old and new equal in length.CString strZap("C--");
    int n = strZap.Replace('-', '+');
    ASSERT(n == 2);
    ASSERT(strZap == "C++");//Second example, old and new are of different lengths.CString strBang("Everybody likes ice hockey");
    n = strBang.Replace("hockey", "golf");
    ASSERT(n == 1);
    n = strBang.Replace("likes", "plays");
    ASSERT(n == 1);
    n = strBang.Replace("ice", NULL);
    ASSERT(n == 1);
    ASSERT(strBang == "Everybody plays  golf");// note that you now have an extra space in your
    // sentence. To remove the extra space, include it 
    // in the string to be replaced, i.e.,"ice ".
      

  3.   

    Your question is strange. If the string is just like you provide, I think it must be wrong. Because '\' is a escape char, so the string you provided has no '\'; escape char is used just in case of const string.