Const char to C-type String problem

Problem just as simple as question: there is an 'if' and depending on result, file address will be assigned. I've tried as following:
1
2
3
4
5
6
7
8
9
char z[100];
int a;
ifstream input;
...
if (a==1)
z="C:\\Program Files\\Myprog\\In1.dat";
else z="C:\\Program File\\Myprog\\In2.dat";
input.open(z);
...

... But compiler gives me 'incompatible types of assignment of 'const char[xx]' to 'char [yy]'' error.
What should I do?
Thanks in advance.
Last edited on
char arrays cannot be assigned in that way.

Either change the type of z to std::string (in which case lines 6 and 7 are ok) or use strcpy (or strncpy).

Note also that line 5 is an assignment not a comparison.
Sorry... This was because I was writing in hurry. But I noticed that trying to open file using x.open(c++typestream) would return error as well, at least on my compiler.
Last edited on
input.open( z.c_str() )

if you change the type of z to std::string.
Thanks for this function. This I was looking for ;)
Last edited on
Topic archived. No new replies allowed.