Amit
asked on
error in string handling
can somebody tell me what's wrong with this ?
__________________________
string x1,filename;
char t[]="C:\\";
char ext[]=".txt";
cout << "Enter x1";
cin >>x1;
filename=strcat(t,x1.c_str
filename=strcat(filename.c
cout << endl<< "Filename= " <<filename;
ASKER
filename=strcat(filename.c _str(),ext );
it say this line has error in it
error C2664: 'strcat' : cannot convert parameter 1 from 'const char *' to 'char *'
Conversion loses qualifiers
it say this line has error in it
error C2664: 'strcat' : cannot convert parameter 1 from 'const char *' to 'char *'
Conversion loses qualifiers
Your usage of the variable 'filename' invokes a conflict. On one hand, you're passing it to strcat () as a 'const char *', but you also try to use it as the receiving field which is a 'char *'.
Use another variable for the first parameter or the receiving field.
Kent
ASKER
couldn't get it to work, could you show me.
string x1,filename, temp;
char t[]="C:\\";
char ext[]=".txt";
cout << "Enter x1";
cin >>x1;
temp=strcat(t,x1.c_str());
filename=strcat(temp.c_str
cout << endl<< "Filename= " <<filename;
ASKER
Its not working, I use VC++
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Sorry, if you have another string named filename, you should change:
x1 = t + x1 + ext;
To:
filename = t + x1 + ext;
Same concept, just different variable. Hope this helps.
x1 = t + x1 + ext;
To:
filename = t + x1 + ext;
Same concept, just different variable. Hope this helps.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
What happens when you compile / run it?