English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

Can any one tell me about the concatination function of C++ out of " strcat ".
I want to concate the Integer with string.

2006-10-31 00:20:12 · 3 answers · asked by Abd-ul-Rehman 2 in Computers & Internet Programming & Design

3 answers

you need to convert the integer to a char string, then concantenate. you can use itoa() function to do the conversion.
example:

char mystring[] = "testing ";
int myint = 123;
char temp[10];

itoa(myint, temp, 10);
strcat(mystring, temp);

just off the top of my head, but I think its right.

2006-10-31 00:59:04 · answer #1 · answered by justme 7 · 0 1

Something like this:
#include
...
inline string itos (int n) {stringstream ss; ss< ..

then you can just do things like

string s = "some string";
s+=itos(125);

etc.

2006-10-31 01:37:46 · answer #2 · answered by n0body 4 · 1 0

I'm writing the program in C, plz do the changes necessary to make the code in C++. Just use 'cout' instead of 'printf' & use 'cin' instead of 'scanf'. Okay ...


//equivalent function of "strcat"

#include

main()
{
char s[25],x[25],t[50];

clrscr();
printf("enter string1");
gets(s);
printf("enter string2");
gets(x);
xstrcat(s,x);
getch();
}


xstrcat(char s[25],char x[25])
{
char t[50];
int n,n1,i,j;
n=strlen(s);
n1=strlen(x);
for(i=0;i {
t[i]=s[i];
}
for(i=n, j=0; i {
t[i]=x[j];
}
t[n+n1]='\0';
puts(t);
}

2006-10-31 00:35:18 · answer #3 · answered by Innocence Redefined 5 · 0 2

fedest.com, questions and answers