概述
函数返回C风格的字符串:
函数无法返回一个字符串,可以返回一个字符串的地址,这样做的效率更高。
#include <iostream>
char* buildstr(char c,int n);
int main()
{
using namespace std;
int times;
char ch;
cout << "Enter a character: ";
cin >> ch;
cout << "Enter an integer: ";
cin >> times;
char* ps = buildstr(ch,times);
cout << ps << "DONE-" << ps << endl;
return 0;
}
char* buildstr(char c, int n)
{
char* pstr = new char[n+1];
pstr[n] = '