//-------------------------------------
//this code is for testing
# include <stdio.h>
# include <stdlib.h>
# include <math.h>
# include <iostream>
# include <fstream>
# include <string>
# include <string.h>
#include <iomanip>
using namespace std;
/*
/*
int start = 1, stop = 4, step = 1;
int N = 2;
int xgrid,ygrid,zgrid,grid;
double xlo, xhi;
double ylo, yhi;
double zlo, zhi;
//reading
int test_in (FILE *fp, double *l1,double *l2,double *l3,double *l4){
//long istep,numatoms,i;
char temp[256];
while(feof(fp) == 0){
fgets(temp,256,fp);//read one line
for (int i = 0; i< N; i++) {
fscanf(fp,"%lf%lf%lf%lf \n",&l1[i],&l2[i],&l3[i],&l4[i]);
}
}
return (0);
}
int main(){
double *l1; double *l2;double *l3;double *l4;
int istep;
l1 = (double*)malloc(N*sizeof(double));
l2 = (double*)malloc(N*sizeof(double));
l3 = (double*)malloc(N*sizeof(double));
l4 = (double*)malloc(N*sizeof(double));
FILE * fp; char fn[256];
ofstream outfile0("readfilename.dat",ios::out);
ofstream outfile1("final.txt",ios::out);
for (istep = start; istep < stop + 1; istep += step) {
sprintf(fn, "%d.txt",istep);
fp = fopen(fn,"r");
//read in on snapshot
if (fp) {
test_in (fp,l1,l2,l3,l4);
fclose(fp);
}
else{
fprintf(stderr,"there isn't the file %d.txt\n",istep); fflush(stderr);
}
//print
outfile0<<"now is reading txt : "<<istep <<" "<<endl;
//
//if(istep == outstep){
outfile1<<"l1 l2 l3 target \n"<<endl;
for (int i = 0; i<4; i++) {
outfile1<<l1[i]<<" "<<l2[i]<<" "<<l3[i]<<" "<<l4[i]<<" "<<endl;
}
}
outfile0.close();
outfile1.close();
free(l1);free(l2); free(l3);
free(l4);
cout<<" ........finish........."<<endl;
return(1);
}
*/
/*
a[2][3][1];
1 2 3
4 5 6
a[2][3][0];
7 8 9
10 11 12
*/
/*
int main(){
int (*cp)[2][3] = new int [3][3][4];//创建一个动态的三维数组
for (int i = 0;i<2;i++)//给数组的每一个元素赋值
for(int j = 0;j<3;j++)
for(int k = 0; k<4; k++){
*(*(*(cp + i) +j) + k) = (i * 100 + j * 10 + k) ;
}
for(int i = 0;i<7;i++){
for(int j = 0;i<9 ;i++){
for(int k = 0;k<8; k++){
cout<<cp[i][j][k]<<" ";
cout << endl;
}
cout << endl;
}
}
delete[] cp;
return 0;
}
*/
#include <iostream>
using namespace std;
int main() {
int a[2][2][2]={
1,2,3,4,5,6,7,8};
int b[2][3] = {
11,12,13,14,15,16};
int **p;
int c[2]={
1,2};
int *pp;
/*
11,12
13,14
*/
p = (int **) malloc(2 * sizeof(int *));
for(int y=0;y<3;y++)
{
p[y]=(int *)malloc(sizeof(int));
cout<<"p["<<y<<"]="<<p[y]<<endl;
}
for(int i=0;i<2;i++)
{
for(int j=0;j<3;j++)
{
/*for(int k=0;k<2;k++)
{
cout<<a[j][i][k]<<endl;
}*/
//cout<<"b["<<i<<"]["<<j<<"] = "<<b[i][j]<<" ";
//p=b;
p[i][j]=b[i][j];
//cout<<" "<<*(*(p+i)+j);
cout<<" "<<p[i][j];
}
cout<<endl;
}
}
二维
猜你喜欢
转载自blog.csdn.net/qq_43689832/article/details/105136532
今日推荐
周排行