String to char

This is a discussion on String to char within the C++ Programming forums, part of the General Programming Boards category; What am i missing here? How do I reinterpret the string to char for use with the fileobject.open? I'll slap ...

  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,812
    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, 11:04 AM
  2. char Handling, probably typical newbie stuff
    By Neolyth in forum C Programming
    Replies: 16
    Last Post: 06-21-2009, 05:05 AM
  3. Replies: 8
    Last Post: 04-25-2008, 03:45 PM
  4. String issues
    By The_professor in forum C++ Programming
    Replies: 7
    Last Post: 06-12-2007, 10:11 AM
  5. Linked List Help
    By CJ7Mudrover in forum C Programming
    Replies: 9
    Last Post: 03-10-2004, 10:33 PM

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