How to change this Error

I made this code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <iostream>
#include <string>
using namespace std;

int main ()
{
        const char a[] = "C:\\Users\\Darth Bane\\Desktop\\Gfx Stuff\\metaknightcopy.bmp";
  string b;
  cout << "What's your PSP Driver? ";
  getline (cin, b);
        FILE* in = fopen( a, "rb" ) ;
        FILE* out = fopen( b, "wb" ) ;
      system("PAUSE");
  return 0;
}
And I get this error in line 13
C:\Users\Darth Bane\Desktop\Coder Stuff\Get Person Input.cpp cannot convert `std::string' to `const char*' for argument `1' to `FILE* fopen(const char*, const char*)

How would I fix this?
Use std::string::c_str()
fopen( a.c_str(), "rb" ) ;

BTW, if you are using C++ why don't use fstreams?
I'm not the Best At C++ I'm still learning. And I haven't gotten to fstreams yet. I've almost stopped in the middle of Classes (II) and Polymorphism. So I'm still doing the basics.

And I'm wanting to to go to copy a file to another Driver

Ok and I edited the FILE* in = fopen( a, "rb" ) ;with what you put and I got actually MORE errors. I got

11 C:\Users\Darth Bane\Desktop\Coder Stuff\Get Person Input.cpp request for member `c_str' in `a', which is of non-class type `const char[57]'


And
12 C:\Users\Darth Bane\Desktop\Coder Stuff\Get Person Input.cpp cannot convert `std::string' to `const char*' for argument `1' to `FILE* fopen(const char*, const char*)'


And When I edit the other FILE* out = fopen( b, "wb" ) ; I get the same last error

quote]11 C:\Users\Darth Bane\Desktop\Coder Stuff\Get Person Input.cpp request for member `c_str' in `a', which is of non-class type `const char[57]' [/quote]
Last edited on
Sorry, 'a' is already a C string:
1
2
FILE* in = fopen( a, "rb" ) ;
FILE* out = fopen( b.c_str(), "wb" ) ;
thank you so much Bazzy. You don't know how much you helped me
Topic archived. No new replies allowed.