12.23
#include <iostream>
#include <cstring>
#include <memory>
using namespace std;
int main()
{
const char *s1 = "string 1 ";
const char *s2 = "string 2 ";
char *r = new char[strlen(s1) + strlen(s2) + 1];
strcpy(r, s1);
strcat(r, s2);
cout << r << endl;
const string s3 = "string 3 ";
const string s4 = "string 4 ";
strcpy(r, (s3+s4).c_str());
cout << r << endl;
delete [] r;
return 0;
}
12.24
#include <iostream>
#include <memory>
using namespace std;
int main()
{
char *r = new char[8];
size_t index = 0;
char c;
while (cin.get(c)) {
if (isspace(c))
break;
r[index++] = c;
if (index == 7)
break;
}
r[index] = '\0';
cout << r << endl;
delete [] r;
return 0;
}<