CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Apr 2009
    Posts
    21

    file.open(address); // ERROR

    I have a problem.

    My program is prompting the user for a file address like this:

    // ...
    string address;
    cout << "Enter file address:\n";
    cin >> address;
    file.open(address);
    // ...

    But this is causing me an error. Anybody has any suggestions?

    Thanks!

  2. #2
    Join Date
    Apr 1999
    Posts
    27,449

    Re: file.open(address); // ERROR

    The open() function takes a const char*, not a std::string.
    Code:
    file.open(address.c_str(), /* other arguments */);
    Secondly, you need to specify the mode to open the file in where I put /* other arguments */.

    Regards,

    Paul McKenzie

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