none
C++ opening a file in using fstream

    Question

  • Hello,

     Im trying to open a file in a folder on my desktop with windows 7

    #include <fstream>

    int main()

    {

    ifstream infile;

    infile.open("C:\Users\jeff\desktop\test\input.txt");

    }

    No complie errors but the Users is underline in red and when highlighted it states

    Error: incorrectly formed universal character name

    the program does not open the file

    I think it would be the right path when i click properties on the folder.

    Thursday, February 16, 2012 6:11 AM

Answers

  • Hello,

     Im trying to open a file in a folder on my desktop with windows 7

    #include <fstream>

    int main()

    {

    ifstream infile;

    infile.open("C:\Users\jeff\desktop\test\input.txt");

    }

    No complie errors but the Users is underline in red and when highlighted it states

    Error: incorrectly formed universal character name

    the program does not open the file

    I think it would be the right path when i click properties on the folder.

    when you need to use \ in a string in c++ you have to type \\ instead of \

    so the answer is: infile.open("C:\\Users\\jeff\\desktop\\test\\input.txt");

    • Marked as answer by xoskeleton Friday, February 17, 2012 6:58 AM
    Thursday, February 16, 2012 9:38 AM
  • >infile.open("C:\Users\jeff\desktop\test\input.txt");

    infile.open("C:\\Users\\jeff\\desktop\\test\\input.txt");

    - Wayne
    • Proposed as answer by rp_suman Thursday, February 16, 2012 5:30 PM
    • Marked as answer by xoskeleton Friday, February 17, 2012 6:58 AM
    Thursday, February 16, 2012 8:49 AM
    • Proposed as answer by rp_suman Thursday, February 16, 2012 5:30 PM
    • Marked as answer by xoskeleton Friday, February 17, 2012 7:00 AM
    Thursday, February 16, 2012 6:58 AM

All replies

    • Proposed as answer by rp_suman Thursday, February 16, 2012 5:30 PM
    • Marked as answer by xoskeleton Friday, February 17, 2012 7:00 AM
    Thursday, February 16, 2012 6:58 AM
  • >infile.open("C:\Users\jeff\desktop\test\input.txt");

    infile.open("C:\\Users\\jeff\\desktop\\test\\input.txt");

    - Wayne
    • Proposed as answer by rp_suman Thursday, February 16, 2012 5:30 PM
    • Marked as answer by xoskeleton Friday, February 17, 2012 6:58 AM
    Thursday, February 16, 2012 8:49 AM
  • Hello,

     Im trying to open a file in a folder on my desktop with windows 7

    #include <fstream>

    int main()

    {

    ifstream infile;

    infile.open("C:\Users\jeff\desktop\test\input.txt");

    }

    No complie errors but the Users is underline in red and when highlighted it states

    Error: incorrectly formed universal character name

    the program does not open the file

    I think it would be the right path when i click properties on the folder.

    when you need to use \ in a string in c++ you have to type \\ instead of \

    so the answer is: infile.open("C:\\Users\\jeff\\desktop\\test\\input.txt");

    • Marked as answer by xoskeleton Friday, February 17, 2012 6:58 AM
    Thursday, February 16, 2012 9:38 AM
  • Thanks guys! It works now!

    Friday, February 17, 2012 7:01 AM