Image

Programs - C++ - String Handling

Program:

#include<string.h>
#include<cassert.h>
using namespace std;

int main() {
string s1="This ";
string s2=("That ");
string s3=("The other ");
// operator+ concatenates strings
 s1 = s1 + s2;
 assert(s1 == "This That ");
// Another way to concatenates strings
 s1 += s3;
 assert(s1 == "This That The other ");
// You can index the string on the right
 s1 += s3 + s3[4] + "ooh lala";
 assert(s1 == "This That The other The other "
    "ooh lala");

getch();
}