源码如下:
// ex8-4.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include
#include
using namespace std;
struct stringy{
char * str;
int ct;
};
char * set(stringy & st, char * ch);
void show(const stringy & st, int n=1);
void show(const char * ch, int n=1);
int _tmain(int argc, _TCHAR* argv[])
{
cout << "ksdfh" << endl;
stringy beany;
char testing[] = "Reality isn't what is used to be.";
char * pt=set(beany, testing);
delete[] pt;
show(beany);
show(beany, 2);
testing[0] = 'D';
testing[1] = 'U';
show(testing);
show(testing, 3);
show("done!");
return 0;
}
char * set(stringy & str, char * ch)
{
char * pt = new char[];
pt = ch;
str.str = pt;
str.ct = strlen(str.str);
return pt;
}
void show(const stringy & str, int n)
{
for (int i = 0; i < n; i++)
cout << str.str << endl;
}
void show(const char * ch, int n)
{
for (int i = 0; i < n; i++)
cout << ch << endl;
}
求解答一下,谢谢!