I have the following code,
char temp[1024];
sprintf(temp,"_%d_%d",type,value);
FileName.append(temp); //<file_name>_1_2
however, i noticed that _1_2 is appended twice and i get an output
of <file_name>_1_2_1_2 instead of just <file_name>_1_2.
Is there any side effect to the append member function call?
Thanks in advance ! ! !
Please post the exact code that shows this issue. The following code
does exactly what you have asked and it also prints exactly what you
want.
#include <cstdio>
#include <iostream>
#include <string>
using namespace std;
int main()
{
int type = 1;
int value = 2;
char temp[1024];
sprintf(temp,"_%d_%d",type,value);
string FileName = "hello.txt";
FileName.append(temp);
cout << FileName << endl;
}
The parts you've omitted could be part of your problem. For example, you
might be calling said function twice, or the way you're printing the
result might be flawed. Try posting a small, complete program that
demonstrates the problem.