Nov 18, 2008 at 9:31am UTC
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 Nov 18, 2008 at 2:45pm UTC
Nov 18, 2008 at 2:36pm UTC
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.
Nov 18, 2008 at 2:44pm UTC
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 Nov 18, 2008 at 2:47pm UTC
Nov 18, 2008 at 2:51pm UTC
input.open( z.c_str() )
if you change the type of z to std::string.
Nov 18, 2008 at 3:12pm UTC
Thanks for this function. This I was looking for ;)
Last edited on Nov 18, 2008 at 3:15pm UTC