Thread: opening files

  1. #1
    Registered User
    Join Date
    Feb 2003
    Posts
    57

    opening files

    hey guys, thanks for the quick response on the other question. i got that to work but i'm still having one other problem. i want to write a program so that you can store a file name in a string variable and then use that variable to open the file. heres an example

    string name;
    name = "washington.txt";
    in_stream.open(name);

    i know its storing the string rigth but for some reason i cant get the file to open using that variable, i get a really long error about conversions. any ideas?

  2. #2
    Registered User abrege's Avatar
    Join Date
    Nov 2002
    Posts
    369
    Code:
    char *name = "washington.txt";
    in_stream.open(name);
    I am against the teaching of evolution in schools. I am also against widespread
    literacy and the refrigeration of food.

  3. #3
    Registered User
    Join Date
    Nov 2001
    Posts
    1,348
    Another solution is c_str().

    theFile.open(theString.c_str());

    Kuphryn

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Opening ASCII files in C?
    By Mavix in forum C Programming
    Replies: 6
    Last Post: 04-25-2007, 02:23 PM
  2. Need help opening a series of files
    By ramparts in forum C Programming
    Replies: 9
    Last Post: 11-14-2006, 05:49 PM
  3. Opening files with UNICODE file names
    By decohk in forum Linux Programming
    Replies: 2
    Last Post: 11-09-2006, 05:25 AM
  4. opening files
    By angelic79 in forum C Programming
    Replies: 3
    Last Post: 10-19-2004, 06:52 AM
  5. Opening files - Giving options?
    By wwwGazUKcom in forum C++ Programming
    Replies: 3
    Last Post: 09-18-2001, 07:06 AM