我创造了一个列表, 并在列表中输入了一些值。 我的列表将内容复制成一个阵列, 然后打印。 我的问题是, 我如何删除我创建的列表?
这是我的代码:
void main()
{
std::list<char> list;
while (1)
{
char in=0;
while(1)
{
scanf("%c",&in);
if(in==
) break;
list.push_back(in);
}
char* array=new char[list.size()]; // create a dynamic array
list<char> first;
std::copy(list.begin(),list.end(),array); // copy the data
for (int i=0 ; i<list.size() ; i++) printf("%c",array[i]);
printf("
size of array is: %d
", list.size());
delete [] array; // destroy the dynamic array
}
}