C++ C++;指针范围
我正在尝试使用我在主函数的另一个函数中创建的数组C++ C++;指针范围,c++,arrays,C++,Arrays,我正在尝试使用我在主函数的另一个函数中创建的数组 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 =
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;
}
现在我如何在我的主函数中使用这两个字符串数组的内容呢?例如,我需要使用str.find()
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;
}
谢谢大家! 使用
运算符
key[position].find( "xyz" ) ;
另外,由于您是手动管理内存,所以一旦使用,您需要释放资源,以避免内存泄漏
delete [] key;
delete [] morse ;
我不确定这是否是OP真正想要的。key是一个数组,可能是key[index].find(“xyz”)?@TonyJiang Opps对不起,修复了很抱歉混淆。但我认为我的问题不清楚。我试图在我的主函数中搜索key和morse,但morse和key是在我使用“createArray()”之后才创建的。@Steven所以在创建这些数组之后,使用上面的方法,有什么问题吗?我不知道键
是否应该出现在morse
中,反之亦然,只要使用for循环来循环位置
,依此类推