forked from pezy/CppPrimer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ex12_23.cpp
29 lines (26 loc) · 817 Bytes
/
ex12_23.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
//
// ex12_23.cpp
// Exercise 12.23
//
// Created by pezy on 12/30/14.
// Copyright (c) 2014 pezy. All rights reserved.
//
// Write a program to concatenate two string literals, putting the result in a
// dynamically allocated array of char.
// Write a program to concatenate two library strings that have the same value
// as the literals used in the first program.
#include <iostream>
#include <string>
#include <string.h>
int main()
{
// dynamically allocated array of char
char* concatenate_string = new char[255]();
strcat(concatenate_string, "hello ");
strcat(concatenate_string, "world");
std::cout << concatenate_string << std::endl;
delete[] concatenate_string;
// std::string
std::string str1{"hello "}, str2{"world"};
std::cout << str1 + str2 << std::endl;
}