如何将来自用户的数据输入到2d数组中并输入到用户c++; 所以我对C++中的2D数组比较陌生,我知道我做了一些错误的事情,但是我不确定什么。 #include <iostream> using namespace std; int main(){ string favBands[10][2]; cout << "Welcome to the favorite band printer outer!" << endl; int count = 1; string band; string song; for(int i = 0; i < 10; i++){ for(int j = 1; j < 2; j++){ cout << "Enter your number " << count << " band:\n" << endl; count += 1; cin >> band; favBands[i][j] = band; cout << "Enter " << favBands[i][j] << "'s best song:\n" << endl; cin >> song; favBands[i][j] = song; } } }

如何将来自用户的数据输入到2d数组中并输入到用户c++; 所以我对C++中的2D数组比较陌生,我知道我做了一些错误的事情,但是我不确定什么。 #include <iostream> using namespace std; int main(){ string favBands[10][2]; cout << "Welcome to the favorite band printer outer!" << endl; int count = 1; string band; string song; for(int i = 0; i < 10; i++){ for(int j = 1; j < 2; j++){ cout << "Enter your number " << count << " band:\n" << endl; count += 1; cin >> band; favBands[i][j] = band; cout << "Enter " << favBands[i][j] << "'s best song:\n" << endl; cin >> song; favBands[i][j] = song; } } },c++,arrays,multidimensional-array,C++,Arrays,Multidimensional Array,我能够完成所有这些,但当我尝试向用户打印阵列时,问题就出现了。我想我的问题可能在于如何将用户数据输入到数组中,但我不确定如何修复它。谢谢 请允许我建议使用两个单独的数组,而不是2D数组,一个用于乐队,一个用于歌曲,然后将歌曲录制下来,如下所示: #include <iostream> using namespace std; int main() { string favBands[10]; string favSongs[10

我能够完成所有这些,但当我尝试向用户打印阵列时,问题就出现了。我想我的问题可能在于如何将用户数据输入到数组中,但我不确定如何修复它。谢谢

请允许我建议使用两个单独的数组,而不是2D数组,一个用于乐队,一个用于歌曲,然后将歌曲录制下来,如下所示:

    #include <iostream>
    using namespace std;
    int main() {
        string favBands[10];
        string favSongs[10];

        cout << "Welcome to the favorite band printer outer!" << endl;

        int count = 1;
        string band;
        string song;
        for (int i = 0; i < 10; i++) {
            cout << "Enter your number " << count << " band:\n" << endl;
            count += 1;
            cin >> band;
            favBands[i] = band;
            cout << "Enter " << favBands[i] << "'s best song:\n" << endl;
            cin >> song;
            favSongs[i] = song;
            cout << "Your favorite song by " << favBands[i] << " is " << favSongs[i] << ".\n";
        }
    }
#包括
使用名称空间std;
int main(){
字符串favBands[10];
弦乐歌曲[10];

cout请允许我建议使用两个单独的数组而不是2D数组,一个用于乐队,一个用于歌曲,然后对歌曲进行cout'ing,如下所示:

    #include <iostream>
    using namespace std;
    int main() {
        string favBands[10];
        string favSongs[10];

        cout << "Welcome to the favorite band printer outer!" << endl;

        int count = 1;
        string band;
        string song;
        for (int i = 0; i < 10; i++) {
            cout << "Enter your number " << count << " band:\n" << endl;
            count += 1;
            cin >> band;
            favBands[i] = band;
            cout << "Enter " << favBands[i] << "'s best song:\n" << endl;
            cin >> song;
            favSongs[i] = song;
            cout << "Your favorite song by " << favBands[i] << " is " << favSongs[i] << ".\n";
        }
    }
#包括
使用名称空间std;
int main(){
字符串favBands[10];
弦乐歌曲[10];

cout您将只需要一个for循环。请参阅,我们正在为10个用户存储数据。对于每个用户,我们将在
索引0
索引1
处获取两个数据。因此,我们不需要第二个for循环。请观察代码并询问您是否仍然有任何混淆。我也将很高兴找到答案

#include <iostream>
using namespace std;

 int main(){
string favBands[10][2];

cout << "Welcome to the favorite band printer outer!" << endl;

int count = 1;
string band;
string song;
for(int i = 0; i < 10; i++)
{
  cout << "Enter your number " << count << " band:\n" << endl;
  count += 1;
  cin >> band;
  favBands[i][0] = band;



  cout << "Enter " << favBands[i][0] << "'s best song:\n" << endl;
  cin >> song;
  favBands[i][1] = song;

  } 
 }
#包括
使用名称空间std;
int main(){
字符串favBands[10][2];

cout您将只需要一个for循环。请参阅,我们正在为10个用户存储数据。对于每个用户,我们将在
索引0
索引1
处获取两个数据。因此,我们不需要第二个for循环。请观察代码并询问您是否仍然有任何混淆。我也将很高兴找到答案

#include <iostream>
using namespace std;

 int main(){
string favBands[10][2];

cout << "Welcome to the favorite band printer outer!" << endl;

int count = 1;
string band;
string song;
for(int i = 0; i < 10; i++)
{
  cout << "Enter your number " << count << " band:\n" << endl;
  count += 1;
  cin >> band;
  favBands[i][0] = band;



  cout << "Enter " << favBands[i][0] << "'s best song:\n" << endl;
  cin >> song;
  favBands[i][1] = song;

  } 
 }
#包括
使用名称空间std;
int main(){
字符串favBands[10][2];

cout
favBands[i][j]=band;
favBands[i][j]=song;
都写在同一个点上。其余的你应该能够通过调试器或在一张纸上一步一步地完成程序。favBands[i][j]=band;
favBands[i][j]=歌曲,两个都写到同一个地方。如果你用调试器或在一张纸上通过程序,其余的你应该能够自己确定。应该工作。考虑使用一个聚集乐队和歌曲的结构的一个数组。几乎总是使书在搜索和排序进入时更容易管理。任务。这样做要容易得多,但是我试着用2D数组来练习,但是谢谢你的建议。应该工作。考虑使用一个聚集乐队和歌曲的结构数组。几乎总是让书在搜索和排序进入任务时更容易管理。这将是很多。这样做比较容易,但我正在尝试使用2d阵列进行练习,但感谢您的建议!