C + + uses pointer arrays and two-dimensional arrays to generate two-dimensional space, storing data and releasing it. Practice New/delete, new[]/delete[]

Source: Internet
Author: User

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[]

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.