Two-dimensional space is generated by pointer array and two-dimensional array, and data is stored and released. For example, the data is as follows:
Use the next fgetc ()
1#include <iostream>2#include <stdio.h>3 using namespacestd;4 5 6 intMain ()7 {8 #if0//generating two-dimensional array storage9file* fp = fopen ("G:\\qtcode\\temp.txt","R");Ten One //char buf[3][10] ={0}; A Char(*BUF) [Ten] =New Char[3][Ten]; - - intI,j,ch; the for(i =0;i<3; i++) - { - for(j =0;j<8; j + +) - { +CH =fgetc (FP); - if(ch = ='\ n'|| ch = =EOF) + Break; ABUF[I][J] =ch; at } -BUF[I][J] =' /'; - } - - for(i =0;i<3; i++) - { incout<<buf[i]<<Endl; - } to Delete[]buf; + fclose (FP); - #endif the * #if1//generating pointer array storage $file* fp = fopen ("G:\\qtcode\\temp.txt","R");Panax Notoginseng - Char**buf =New Char*[3]; the intI,j,ch; + for(i =0;i<3; i++) A { the* (buf+i) =New Char[8] ; + for(j =0;j<8; j + +) - { $CH =fgetc (FP); $ if(ch = ='\ n'|| ch = =EOF) - Break; -BUF[I][J] =ch; the } -BUF[I][J] =' /';Wuyi } the for(i =0;i<3; i++) - { Wucout<<buf[i]<<"***"<<Endl; - Delete[] (* (buf+i)); About //delete[] (buf[i]); $ } - Delete[]buf; - fclose (FP); - A #endif + return 0; the}
. C + + uses pointer arrays and two-dimensional arrays to generate two-dimensional space, storing data and releasing it. Practice New/delete, new[]/delete[]