Conversion of char to a string

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • maabar
    New Member
    • Aug 2006
    • 6

    Conversion of char to a string

    Hi, I need to know how could I use the class ifstream if I want to pass a string to its constructor?

    For example, if I have the following codes:

    string name = "file.txt";

    ifstream f(name);

    the compiler says that ifstream doesn't take string as an argument, so what do I need to do to use the above codes? I don't want to use ifstream f("file.txt") ;

    Thanks
  • rgb
    New Member
    • Aug 2006
    • 37

    #2
    have you tried:

    char* name;
    name = "file.txt";
    ifstream f(name);

    Comment

    • Banfa
      Recognized Expert Expert
      • Feb 2006
      • 9067

      #3
      or

      char name[] = "file.txt";
      ifstream f(name);

      saving the whole size of a pointer in program data.

      Comment

      • MrJay
        New Member
        • Aug 2006
        • 6

        #4
        You can still try out this,
        Code:
        string line = "first.txt";
        istringstream is(line);
        istringstream is defined in <sstream> header file

        Comment

        Working...