string::append appening twice

R

Rahul

Hi Everyone,

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 ! ! !
 
N

Neelesh

Hi Everyone,

 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;
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,277
Latest member
VytoKetoReview

Latest Threads

Top