Thread: File input - with vars

  1. #1

    Exclamation File input - with vars

    Hello....I have a quick question:

    How do you open a file for input, using a var.
    eg. I store "" in the var MapFile.
    then I use:

    ifstream File1; (MapFile);

    Why doesn't this work?

  2. #2
    of Zen Hall zen's Avatar
    Join Date
    Aug 2001
    Is in your local directory? What variable type is MapFile ?

  3. #3


    Yes the is in the same dir as the project file, and the MapFile is a string...

    When I use

    ifstream File1; ("");

    instead of

    ifstream File1; (MapFile);

    it works fine...

    Also the file is opened in a seperate function:
    from the main() i call


    wich uses the function:

    void LoadMap(string MapFile)
    ifstream File1; (MapFile);

  4. #4
    Registered User
    Join Date
    Sep 2001
    It is a string, as defined in cstring.h?

    With this data type, iut will NOT automatically convert to a const char * which is what you need. To get that, you'd need to use;

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. can someone help me with these errors please code included
    By geekrockergal in forum C Programming
    Replies: 7
    Last Post: 02-10-2009, 02:20 PM
  2. sequential file program
    By needhelpbad in forum C Programming
    Replies: 80
    Last Post: 06-08-2008, 01:04 PM
  3. Can we have vector of vector?
    By ketu1 in forum C++ Programming
    Replies: 24
    Last Post: 01-03-2008, 05:02 AM
  4. C++ std routines
    By siavoshkc in forum C++ Programming
    Replies: 33
    Last Post: 07-28-2006, 12:13 AM
  5. what does this mean to you?
    By pkananen in forum C++ Programming
    Replies: 8
    Last Post: 02-04-2002, 03:58 PM