我正在尝试在主函数中使用在另一个函数中创建的数组。

int main()
{
    string *key;
    string *morse;
    createArray(fileName, &key, &morse, size);
}

void createArray(string fileName, string **key, string **morse, int size)
{
    *key = new string[size];
    *morse = new string[size];
    (*key)[position-1] = currentKey;
    (*morse)[position-1] = currentMorse;
}


现在如何在我的主函数中使用这两个字符串数组的内容?例如,我需要在main()函数中使用str.find();

谢谢!

最佳答案

使用.运算符

key[position].find( "xyz" ) ;


另外,由于您是手动管理内存,因此一旦使用就需要释放资源,以避免内存泄漏

delete [] key;
delete [] morse ;

07-24 09:46
查看更多