【发布时间】:2019-09-11 13:13:01
【问题描述】:
我在 C++ 中有一个基本的二维数组。我想删除一个特定的列并将下一列放在它的位置。我的数组是
姓名[ ] 商标[ ]
FNAME[ ] REG#[ ]
Name 和 FNAME 在第一个二维数组(字符串)中,而 Tmarks 和 reg # 在第二个二维数组(int)中
我已经在 StackOverflow 上尝试过解决方案,但无法正常工作。
#include <iostream>
using namespace std;
#define ROW 2
#define COL 70
void input(string data[][COL], int moredata[][COL], int n)
{
for (int i = 0; i < ROW; i++)
{
for (int j = 0; j < n; j++)
{
if (i == 0)
{
cout << " Name of Student # : " << j + 1 << endl;
cin >> data[i][j];
cout << "Total Marks out of 600 of student # " << j + 1 <<
endl;
cin >> moredata[i][j];
}
if (i == 1)
{
cout << " Father Name of Student # " << j + 1 << endl;
cin >> data[i][j];
cout << "Reg # of student # " << j + 1 << endl;
cin >> moredata[i][j];
}
}
}
}
int main()
{
int n;
string data[ROW][COL] = {};
int moredata[ROW][COL] = {};
cout << "NO of Students: ";
do
{
cin >> n;
} while (n > 70 || n < 0);
input(data, moredata, n); //input function already created.
现在我想做一个删除单列的函数。
【问题讨论】:
-
想想基本情况,你想从数组中删除一个元素。由于您的表是一个数组数组,因此您只需对每一行重复此基本任务。您还可以发布您已经尝试过的代码吗?如果您不发布那个代码以及您使用它时遇到的错误,那么很难知道您遇到的问题是什么。
标签: c++ algorithm multidimensional-array copy move