i want to add an integer at the end of a given string,and then i want to creat and open a text file of the resulting string.example:name,1,the required path is ("d:\name1.txt).
i use this code but it never works,anybody know why??
char * output;
char * output2;
char *add;
char * add1;
int msgno;
msgno=1;
char name1[20];
stpcpy(name,"name");
output2=new char[2];
ltoa((msgno+1),output2,10);
output2[1]='\0';
output=new char[strlen(name)+2];
stpcpy(output,name);
output=strcat(output,output2);
output[strlen(name)+1]='\0';
add=new char[(strlen(output))+5];
add=strcat(output,".txt");
add[(strlen(name))+5]='\0';
add1=new char[(strlen(add))+4];
add1=strcat("d:\\",add);
add1[(strlen(name))+8]='\0';
obj1.open(add1,ios::out);
obj1.close();
delete output;
delete output2;
delete add;
delete add1;


Sign In
Create Account

Back to top









