gpt4 book ai didi

C++ 多维字符串数组

转载 作者:行者123 更新时间:2023-11-27 22:52:11 24 4
gpt4 key购买 nike

有人可以为我更正这段代码,以便它可以产生正确的输出。代码是显示患者姓名,治疗他/她的医生,他/她接受治疗的房间。

#include <iostream> 
using namespace std;

int main()
{
string bisi[3][4] = {{" ", "DOCTOR 1", "DOCTOR 2", "DOCTOR 3"},
{"ROOM 1", "AFUAH", "ARABA", "JOHNSON"},
{"ROOM 2", "BENJAMIN", "KOROMA", "CHELSEA"}};

for (int row=0; row<3; row++){
for (int col=0; col<4; col++){
cout<<bisi [row][col]<<" "; /*I get error on this line.The angle bracket "<<" Error Message: No operator matches this operand.*/
}
cout<<endl;
}

return 0;
}

最佳答案

你需要改变:

cout << bisi[row] << bisi[col] << " ";

到:

 cout << bisi[row][col] << " ";

bisi 是一个二维数组,bisi[row]bisi[col] 只会打印一个地址

关于C++ 多维字符串数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36305477/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com