#include
#include
using namespace std;
int main(void)
{
char ch;
int i=1;
char *before = new char[1],*temp;
while (cin >> ch)
{
temp = new char[i];
temp[i - 1] = ch;
for (int j = 0; j < i - 1; j++)
temp[j] = before[j];
delete[] before;
before = temp;
++i;
}
for (int j = 0; j < i - 1; j++)
cout << temp[i];
}
最後
for (int j = 0; j < i - 1; j++)
cout << temp[i];
錯了吧,循環變量是j,應該是
for (int j = 0; j < i - 1; j++)
cout << temp[j];
而且temp[i]是一個申請的存儲空間()