Using strcat and strncat. : string function « Data Types « C++ Tutorial






#include <iostream>
using std::cout;
using std::endl;

#include <cstring>
using std::strcat;                                     
using std::strncat;                                     

int main()
{
   char s1[ 20 ] = "123456";
   char s2[] = "abcdefghi";
   char s3[ 40 ] = "";

   strcat( s1, s2 );

   cout << s1 << "\ns2 = " << s2;

   strncat( s3, s1, 6 ); // places '\0' after last character

   cout << s1 << "\ns3 = " << s3;

   strcat( s3, s1 );
   cout << s1 << "\ns3 = " << s3 << endl;
   return 0;
}
123456abcdefghi
s2 = abcdefghi123456abcdefghi
s3 = 123456123456abcdefghi
s3 = 123456123456abcdefghi








2.24.string function
2.24.1.Using strcpy()
2.24.2.Using strncpy()
2.24.3.strcpy, strlen, strcmp, strcat
2.24.4.Convert a string to uppercase.
2.24.5.Using strcat and strncat.
2.24.6.Using strcmp and strncmp
2.24.7.Using strtok
2.24.8.Using strlen