ifstream file name

This is a discussion on ifstream file name within the C++ Programming forums, part of the General Programming Boards category; how do i pull something like this off? Code: int level = 1; std::ifstream map("level" + level + ".map"; so ...

  1. #1
    Registered User
    Join Date
    Jul 2010
    Posts
    8

    ifstream file name

    how do i pull something like this off?

    Code:
    int level = 1;
    
    std::ifstream map("level" + level + ".map";
    so when i detect someone has completed a level i can just change the value of 'level' and repeat the same method.

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,336
    Use a string stream to construct your filename.

    Then use the c_str() method on that object to pass to ifstream as the filename to open.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Jul 2010
    Posts
    8
    thanks i got it working now

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. File Writing Problem
    By polskash in forum C Programming
    Replies: 3
    Last Post: 02-13-2009, 09:47 AM
  2. Formatting a text file...
    By dagorsul in forum C Programming
    Replies: 12
    Last Post: 05-02-2008, 03:53 AM
  3. Inventory records
    By jsbeckton in forum C Programming
    Replies: 23
    Last Post: 06-28-2007, 04:14 AM
  4. C++ std routines
    By siavoshkc in forum C++ Programming
    Replies: 33
    Last Post: 07-28-2006, 12:13 AM
  5. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM

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