在线等 致向数组的指针 如何遍历 关系全家老小吃饭问题 帮忙啊
有这样一个数组,知道指针,想把传到一个函数里面,然后进行遍历,对方就给出了头函数,让我实现,帮忙啊
想不出来怎么办, 求啊,关系全家老小吃饭问题
const char * strs[] = {
"ape", "apes", "apse", "asp", "pas", "pase", "pea",
"peas", "pes", "sae", "sap", "sea", "spa", "spae"
};
Boggle A;
A.solve(strs);
指针 遍历
void Boggle::Solve( const char * a_Grid) const
{
在这里把他们一个一个的打出来 a_Grid 里面的东东
}
const char * strs[] = {
"ape", "apes", "apse", "asp", "pas", "pase", "pea",
"peas", "pes", "sae", "sap", "sea", "spa", "spae",NULL //加一个NULL表示结束,可以用0
};
Boggle A;
A.solve(strs);
void Boggle::Solve( const char ** a_Grid) const
{
assert(a_Grid);//断言指针非空,传入空指针,调试出错。
if(!a_Grid)return ;//保证指针非空。
//在这里把他们一个一个的打出来, a_Grid 里面的东东。
while(*a_Gird){
std::cout<<*a_Gird++ <<std::endl;
}
}
template <int N>
void solve(const char *(&strs)[N])
{
for (int i = 0; i < N; ++i) {
cout << strs[i] << endl;
}
}