Thread: String to char

  1. #1
    Registered User
    Join Date
    Feb 2006
    Posts
    21

    String to char

    What am i missing here? How do I reinterpret the string to char for use with the fileobject.open? I'll slap out quick source for visual. ::baffled::

    Code:
    #include <string>
    #include <iostream>
    #include <fstream>
    
    void LoadFile(string filename) 
    {
         ifstream fileobject;
         fileobject.open(filename, ios::binary);
    }
    
    int main(int argc, char *argv[])
    {
          string filename;
          filename = "test.txt";
          LoadFile(filename);
          return 1;
    }

  2. #2
    Sweet
    Join Date
    Aug 2002
    Location
    Tucson, Arizona
    Posts
    1,820
    Use the c_str method.
    Code:
    filename.c_str()
    Woop?

  3. #3
    Registered User
    Join Date
    Feb 2006
    Posts
    21
    Damn. Should of realised that. Thanks.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Can you help me about tolower() in file
    By nctar in forum C Programming
    Replies: 7
    Last Post: 05-12-2010, 10:04 AM
  2. char Handling, probably typical newbie stuff
    By Neolyth in forum C Programming
    Replies: 16
    Last Post: 06-21-2009, 04:05 AM
  3. Replies: 8
    Last Post: 04-25-2008, 02:45 PM
  4. String issues
    By The_professor in forum C++ Programming
    Replies: 7
    Last Post: 06-12-2007, 09:11 AM
  5. Linked List Help
    By CJ7Mudrover in forum C Programming
    Replies: 9
    Last Post: 03-10-2004, 10:33 PM