CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Mar 2008
    Posts
    7

    [RESOLVED] using a string to open a file for reading

    I'm making a program that does accounting. It's a school project that is self directed since I'm the only one in the class. I'm teaching myself.

    In the program I store each persons data in a txt file with their username as the name of the file. When they enter the username I add it to a string and add .txt on the end. Poof, the file path to the file I need to read data from is created. I do this

    Code:
         ifstream inData;
         inData.open(finalPath);
    finalPath is the string with the file path.

    The compiler doesn't like this. Since a string won't work, how else can I do this?

  2. #2
    Join Date
    Aug 2000
    Location
    West Virginia
    Posts
    7,725

    Re: using a string to open a file for reading

    open() takes a const char * variable ... assuming that finalPath is
    a std::string, call the .c_str() member function ...

    Code:
    inData.open(finalPath.c_str());

  3. #3
    Join Date
    Mar 2008
    Posts
    7

    Re: [RESOLVED] using a string to open a file for reading

    Thank you.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured