问题动态数组 [英] problem dynamic array

查看:64
本文介绍了问题动态数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨 我无法从动态数组中获取一个数字,然后打印出来.
我该怎么办?
输入:2
3
3
0
0
5
1
2
3

代码:

Hi I get a number from dynamic array and then print, I can not.
What do I do?
input:2
3
3
0
0
5
1
2
3

code:

#include<iostream>
using namespace std;
void s(int f[],int d)
{
	cout<<"matris  element i,j   :\ni=";
        cin>>f[0,0];cout<<"j=";cin>>f[0,1];
        f[0,2]=d;
        cout<<"add number not 0 ";
	for(int k=1;k<d+1;k++)
	{   
		cout<<"\n array i="; cin>>f[k,0];
		cout<<"array j=";cin>>f[k,1];
		cout<<"value array ij=";cin>>f[k,2];
		cout<<f[k,2];
	}
	for(int i=1;i<d+1;i++)
	 {
		for(int j=0;j<3;j++)
		cout<<f[i,j];
	    cout<<"\n";
	 }
}
void main()
{
    int w;
	cout<<"number not 0 :";
	cin>>w;
    int *b=new int [w+1,3];
    s(b,w);
}

推荐答案

逗号(,)是列表运算符.数组操作(operator [](int index);)只有一个参数.列表运算符将以以下方式工作:将执行所有操作(用逗号分隔),但最后一个仍然是操作数.
例如,您可以编写int* px = new int [n=calcsize(),n+=8,push(n),42];,最终将像这样:n = calcsize(); n+=8; push(n); int* px = new int [42];.因此,在您的代码中,所有数组操作都使用最后一个逗号后面的参数:
int *b=new int [w+1,3];等于int *b=new int [3];
cin>>f[k,0];等于cin>>f[0];
等等.
也许您可以解释表达方式所能达到的目标.
最好的问候.
The comma (,) is a list operator. The array operation (operator [] (int index);) has only one argument. The list operator will work in following way: all operations (separated by comma) will been executed but still the last is the operand.
For example you can write int* px = new int [n=calcsize(),n+=8,push(n),42]; will finally be the same like: n = calcsize(); n+=8; push(n); int* px = new int [42];. So at your code all your array operations are using the parameter behind the last comma:
int *b=new int [w+1,3]; is equal to int *b=new int [3];
cin>>f[k,0]; is equal to cin>>f[0];
and so on.
Perhaps you can explan what to achive with your expressions.
Best regards.


这篇关于问题动态数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆