Thread: reading from a file depending on variable

  1. #16
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    Is that because there is an extra 0 in the filename? The two pieces of code generate two different filenames, so if one works and one doesn't it's probably because the one that works is creating the correct filename.

  2. #17
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    . . . you could always use something like
    Code:
    filename = "C:\\Dragonways\\Map\\" + mapfile + ".txt";
    cout << filename << endl;
    ifstream readMap(filename.c_str());
    to see the exact filename that is being generated.

    The problem is likely that you have to be exact when you specify a filename, down to the last character. If the file is called "(mapfile variable)0.txt" then your code that doesn't work , well, it won't work.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Basic text file encoder
    By Abda92 in forum C Programming
    Replies: 15
    Last Post: 05-22-2007, 01:19 PM
  2. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM
  3. Reading from file into structs..
    By dankas in forum C Programming
    Replies: 14
    Last Post: 10-16-2002, 10:33 PM
  4. System
    By drdroid in forum C++ Programming
    Replies: 3
    Last Post: 06-28-2002, 10:12 PM