编写一个程序,并编写一个函数 select_last,获得一个二维字符数组 string[ ][15]中最靠后的字符。例如,{“hello”,“neng”,“dong”,“er”} 中,最靠后的字符是‘r’。
遍历数组,找到最后一个string,然后获取最后一个字符
你这里有个逻辑问题,要么是string str[15] = {“hello”,“neng”,“dong”,“er”} ;要么是 char str[][15] = {“hello”,“neng”,“dong”,“er”} ;你现在的写法并不正确,编译会报错的
char select_last()
{
string str[15] = {"hello","neng","dong","er"};
char ch;
for(int i=0;i<15;i++)
{
if(str[i].length() != 0)
ch = str[i][str[i].length()-1];
}
return ch;
}