string *level_two;
클래스에 선언 된 배열을 가져 왔습니다. 클래스 함수에서 동적으로 크기를 할당했습니다.문자열 배열 유지 내용의 크기를 동적으로 변경합니다
level_two = new string [size];
나는 그 크기는 주로 크기가 5이고 내 배열이 5의 크기가 동적으로 선언하고 내가 증가 할 위치 2 위치 3에서 일부 문자열이있는 경우 같은 내용을 유지 크기를 증가 변경해야 위치 2와 3에있는 문자열이 변경없이 크기에 있어야하는 크기의 변화에 따라 크기가 10이됩니다.
어떻게하면됩니까?
PART II :
int temp=0;
temp= final_hash_index_one;
final_hash_index_one = sum % number_of_keys_to_be_hashed;
sum = 0;
cout<<"final_hash_index_one: "<<final_hash_index_one<<endl;
if(final_hash_index_one>temp)
{
string *tmp = new string[final_hash_index_one+1];
std::copy(level_two, tmp, final_hash_index_one+1);
delete [] level_two;
level_two = tmp;
}
if(temp>final_hash_index_one)
{
string *tmp = new string[temp+1];
std::copy(level_two, tmp, final_hash_index_one+1);
delete [] level_two;
level_two = tmp;
}
level_two = new string [final_hash_index_one+1];
level_two[final_hash_index_one] = file_se_uthao;
tab_obj[return_structure_index].z = level_two;
차이점은 무엇입니까 ?? –
@Mat 누가 std :: string이 아니라고 말합니까? 게다가 std :: string의 배열을 사용할 때 메모리 할당에 대해 걱정해야합니다. – Petruza
배열을 사용하면 배열을 인접한 메모리 공간에 저장해야하므로 크기를 * 늘릴 수 없으므로 new로 생성시에만 크기를 설정할 수 있습니다. @Oli가 대답 했으므로 표준 컨테이너를 사용하는 것이 좋습니다. – Petruza