<分区>
二维数组,如何在输入中接受空格?在一维数组中,我认为正确的代码是 cin.getline(array,5)
,但在二维数组中,我无法弄清楚什么是正确的参数。
这是我的代码
#include<iostream>
void display();
char array[2][5];
using namespace std;
int main(){
for (int x = 0; x < 2; ++x) {
for (int y = 0; y < 5; ++y) {
display();
cout << "Enter a value: ";
cin>>array[x][y]; //i want to accept space in input. cin.getline(array[x][y],?)
system("cls");
}
}
display();
}
void display(){
for(int x = 0; x<2; x++){
for(int y = 0; y<5; y++){
cout<<" " <<array[x][y] <<" ";
}
cout<<endl;
}
}
最后,如何限制cin的输入>>?例如,它只允许输入 1 个字符。提前联系