Using #include <fstream> RRS feed

  • Question

  •      So I have visual studio 2015 and am currently taking c++ programming course. One of my assignments is to use fstream to read data from a file to my program. Like I said I am using Studio 2015 and Windows 10. My program and code are all correct, but my program will not run properly because I do not know where to place the inFile which is a .txt file for my .cpp file to read from. Now I thought the .txt file goes into the same file location as the .cpp file but that does not work. I have also tried placing the .txt file into the debug file but that did not work as well. Where do I place this file so the program can function properly?

    Thanks for your input. 

    Wednesday, October 14, 2015 2:26 PM


All replies

  • See the Working Directory setting in your project's debug configuration.  For more information see Project Settings for a C++ Debug Configuration
    Wednesday, October 14, 2015 2:51 PM
  • sorry Scot this did not seem to answer  my question, anything else you can suggest? I need to know the file placement of a text file (which is already named and has data in it) so my .cpp program can read from it and then place it into an out file which is created automatically.
    Thursday, October 15, 2015 4:16 PM
  • If you go into the project properties and look in the Configuration Properties | Debugging you will see the Working Directory.  The default says $(ProjectDir).  To see what that macro means, select Working Directory and then click on the down arrow that appears to the right of the entry. Select Edit and when the dialog box opens click the Macros button.  You can then scroll the list of macros and their definitions to see the expansion of the $(ProjectDir) macro which is where you should put your data file.

    Alternatively, you could specify full paths in your code to reference your input and output files.

    BTW, if you have already placed your data file in the correct location and your program doesn't work properly then it is likely that there is some problem with your code.  You can always post your code so that the community can provide feedback to you
    • Edited by RLWA32 Thursday, October 15, 2015 5:17 PM suggested posting code
    Thursday, October 15, 2015 4:32 PM