reading from a file depending on variable

This is a discussion on reading from a file depending on variable within the C++ Programming forums, part of the General Programming Boards category; Is that because there is an extra 0 in the filename? The two pieces of code generate two different filenames, ...

  1. #16
    Registered User
    Join Date
    Jan 2005
    Posts
    7,344
    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,048
    . . . 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.

Page 2 of 2 FirstFirst 12
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, 02:19 PM
  2. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 10:54 AM
  3. Reading from file into structs..
    By dankas in forum C Programming
    Replies: 14
    Last Post: 10-16-2002, 11:33 PM
  4. System
    By drdroid in forum C++ Programming
    Replies: 3
    Last Post: 06-28-2002, 11:12 PM

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