answersLogoWhite

0

#include<iostream>

#include<string>

int main()

{

// the two strings to concatenate

std::string str1 = "Hello ";

std::string str2 = "world!";

// allocate memory to the concatenated string with null-terminator

char* str3 = new char[str1.size() + str2.size() + 1];

// initialise a moving pointer

char* p = str3;

// copy from the first string

memcpy( p, str1.c_str(), str1.size() );

// advance the pointer

p += str1.size();

// copy from the second string

memcpy( p, str2.c_str(), str2.size() );

// advance the pointer

p += str2.size();

// set the null-terminator

*p = 0;

// print concatenated string

std::cout << str3 << std::endl;

// tidy up

delete [] str3, str3 = NULL;

}

User Avatar

Wiki User

11y ago

What else can I help you with?

Related Questions

Concat a string without using any inbuilt function in java?

Use "+". Example: String string = "does this answer " + "your question?";


How do you concatenate a string?

v can concatenate two string by using a function like: select CONCAT( CONCAT('ename','e_mrks'),"name","marks" from student;


What are the two ways strings can be combined to create a new string?

Concat()


14 Write a program to change the case of the given string?

public class class1{public void changeCase(String str){String str1=str.toUpperCase();String str2=str.toLowerCase();System.out.println(str1);System.out.println(str2);System.out.println("After concatenation "+("to".concat("get").concat("her")));}public static void main(String[] args){class1 c1=new class1();c1.changeCase("Hello");}}


How to perform string operations like concatenation compare etc without using built in functions?

performing string operation using pointers


What is string library functions syntax?

String library function is one which is used to perform an operation in C-programming,without which library functions likestrlen(),strcp(),strcmp(),strdup(),strrev(),etc..,.can be performed


How to capitalize the first letter of a string without using built in C functions?

jst subtract 32 from first character of string to convert it into capital


String reverse program with single string and without using library functions in java?

You can create a separate string initially empty. Then using a loop, start at the end of the string and add it to the end of the other string. At the end of the loop, the other string would contain the reverse.


What are the functions of Atoi itoa and gcvt in C language?

All these are conversion functions - atoi()-string to integer.itoa()-integer to string.gcvt()-double to string


C plus plus library functions for string operations?

You can use "string" class in C++ for string operations or you may use c style string functions as well. #include &lt;string&gt; String class in C++ provides all basic function to operate on strings. you may details descriptin at http://www.cplusplus.com/reference/string/string/


Program to concatenate the two strings without using build in functions?

#include&lt;iostream&gt; #include&lt;string&gt; int main() { using std::string; string a = "hand"; string b = "bag"; string c = a + b; // concatenation }


Define class string and implement all the functions related to strings?

define class string