Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Senior Coder
    Join Date
    Apr 2003
    Location
    England
    Posts
    1,192
    Thanks
    5
    Thanked 13 Times in 13 Posts

    C++ ifstream with a string

    i can use
    ifstream myFile("test.txt");
    but not
    string str = "test.txt";
    ifstream myFile(str);


    im trying to use a function so i sorta need it to get it from a vairable, is there any way to do this?

  • #2
    Regular Coder
    Join Date
    Jul 2002
    Location
    Belgium
    Posts
    124
    Thanks
    0
    Thanked 0 Times in 0 Posts
    try ifstream myFile(str.c_str());
    If you don't succeed at first, redefine succes


  •  

    Posting Permissions

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