Thread: Getting the name of a file reading to program

  1. #1
    Registered User
    Join Date
    Mar 2003
    Posts
    1

    Post Getting the name of a file reading to program

    I'm Working on a project which reads input from a file. I need to find a way to save the filename of the file that is being read into my program. Is there some funtion associated with fstream or another way to get the file name?

    On a related note, Can maps hold 2 strings? I have seen them used effectively in the use of counters, but is it possible to have map<string, string> s ?? The second string would hold the file name of the file that was read in, and the first string would hold the word that was found in the file that was read in, compared to words in another file.

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    > I need to find a way to save the filename of the file that is being read into my program.
    Save it to a variable and use that variable to open the file:
    Code:
    string filename = "blah";
    
    fp.open ( filename.c_str() );
    > Is there some funtion associated with fstream or another way to get the file name?
    No.

    >On a related note, Can maps hold 2 strings?
    Of course.

    -Prelude
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A development process
    By Noir in forum C Programming
    Replies: 37
    Last Post: 07-10-2011, 10:39 PM
  2. opening empty file causes access violation
    By trevordunstan in forum C Programming
    Replies: 10
    Last Post: 10-21-2008, 11:19 PM
  3. Why isn't my program reading my file properly?
    By DCMann2 in forum C Programming
    Replies: 10
    Last Post: 04-23-2008, 01:16 AM
  4. Basic text file encoder
    By Abda92 in forum C Programming
    Replies: 15
    Last Post: 05-22-2007, 01:19 PM
  5. Whats wrong with my file reading program?
    By Alphabird32 in forum C++ Programming
    Replies: 1
    Last Post: 09-08-2002, 03:19 AM