File reading in folders

This is a discussion on File reading in folders within the C++ Programming forums, part of the General Programming Boards category; Right now I can open any text file or whatnot but it needs to be in the same folder as ...

  1. #1
    Registered User
    Join Date
    Jan 2003
    Posts
    38

    File reading in folders

    Right now I can open any text file or whatnot but it needs to be in the same folder as the exe. How do I tell the program not to look there but to look in a folder called maps? I am using MSVC++
    I would like to do this with using just the fstream operators and such if possible.

    the folder maps in in the same folder as the exe

  2. #2
    Registered User
    Join Date
    Nov 2002
    Posts
    1,109
    if you know if the folder is on a certain drive, you could try opening it with ifstream. i.e.
    Code:
    ifstream infile("c:\maps\textfile.txt");
    if you created the folder with your program, you should be able to open a file from that folder. the tricky part is making sure the harddrive is designated with the c: letter. i'm sorry, i can't help you there, but i'm sure there are others that can. hope this helps some.

  3. #3
    Registered User
    Join Date
    Jan 2003
    Posts
    38
    Yea this helps alot ... I wasnt sure of the syntax of just reading from a folder much less on what drive its on... I may be able to not specify and hope it reads from the same directory that the exe is in.

  4. #4
    Registered User
    Join Date
    Jan 2003
    Posts
    38
    AHH I found it I am using MFC and It just so happens that there is a string that is defined when you make a new project called THIS_FILE When I couted the character array it gave me the full directory that the game is in so if i just add \maps to the end of that it will bring my map files into scope. thanks for the help

    Alas it only gives the directory of the .cpp file no matter what machine I run it on =/
    Last edited by CSoFun; 03-11-2003 at 06:36 PM.

  5. #5
    Registered User
    Join Date
    Nov 2002
    Posts
    1,109
    you're welcome. thanks for the info. good thing to know.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. sequential file program
    By needhelpbad in forum C Programming
    Replies: 80
    Last Post: 06-08-2008, 01:04 PM
  2. Formatting the contents of a text file
    By dagorsul in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2008, 12:36 PM
  3. Can we have vector of vector?
    By ketu1 in forum C++ Programming
    Replies: 24
    Last Post: 01-03-2008, 04:02 AM
  4. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 01:53 AM
  5. System
    By drdroid in forum C++ Programming
    Replies: 3
    Last Post: 06-28-2002, 10:12 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21