locked
Illegal characters in path RRS feed

  • Question

  • Someone please explain to me what is wrong with this code:

    StreamReader^ reader = gcnew StreamReader("C:\test.txt");

    C++/CLIL, .net 3.5, windows xp, VS2008

    Friday, March 26, 2010 7:04 PM

Answers

  • The backslash. Either use 2, or use forward slash. Backslash is an escape in C.

    StreamReader^ reader = gcnew StreamReader("C:\\test.txt");

    StreamReader^ reader = gcnew StreamReader("C:/test.txt");

    • Edited by jinzai Friday, March 26, 2010 7:06 PM add code
    • Marked as answer by mscheaf Friday, March 26, 2010 7:09 PM
    Friday, March 26, 2010 7:06 PM

All replies

  • The backslash. Either use 2, or use forward slash. Backslash is an escape in C.

    StreamReader^ reader = gcnew StreamReader("C:\\test.txt");

    StreamReader^ reader = gcnew StreamReader("C:/test.txt");

    • Edited by jinzai Friday, March 26, 2010 7:06 PM add code
    • Marked as answer by mscheaf Friday, March 26, 2010 7:09 PM
    Friday, March 26, 2010 7:06 PM
  • duh, escape characters. Ususally I don't hard code filenames in my stream, this is just for some unit testing. thanks
    Friday, March 26, 2010 7:08 PM