VC + + in TXT file specified location append content method _c language

Source: Internet
Author: User
Tags fread

This article describes the VC + + operation of the text file method, the implementation of TXT file at the specified location inserted content. For VC + + enthusiasts have a certain learning reference value.

The main functional code is as follows:

void Cgotofiledlg::onpaint () {if (Isiconic ()) {CPAINTDC DC (this); SendMessage (Wm_iconerasebkgnd, (WPARAM) DC.
 GETSAFEHDC (), 0);
 int cxicon = GetSystemMetrics (Sm_cxicon);
 int cyicon = GetSystemMetrics (Sm_cyicon);
 CRect rect;
 GetClientRect (&rect); int x = (rect.
 Width ()-Cxicon + 1)/2; int y = (rect.
 Height ()-Cyicon + 1)/2; dc.
 DrawIcon (x, y, M_hicon);
 else {cdialog::onpaint (); } hcursor Cgotofiledlg::onquerydragicon () {return (hcursor) M_hicon;} void Cgotofiledlg::onbutopen () {CFileDialog D LG (true,null,null,ofn_hidereadonly| Ofn_overwriteprompt, "All Files (*. TXT) |*. txt| | ", AfxGetMainWnd ());//The construct file opens the dialog box if (DLG). DoModal () = = IDOK)//Decide whether to press the "open" button {M_path = dlg. GetPathName ();
  Get file path Files *pfile = fopen (M_path, "r+t");//read-write to open file if (pFile)/To determine whether the file is properly open {char pchdata[1000] = {0};//define data buffer Fread (Pchdata,sizeof (char), 1000,pfile);
 Read data to Buffer fclose (pFile);//close File M_file = Pchdata;
 } updatedata (FALSE);
 } void Cgotofiledlg::onbutinsert () {UpdateData (); File *pfile = fopen (M_path, "r+t");//read-write to open files if (pFile)/To determine whether the file is correctly opened {fseek (pfile,m_goto,seek_set);//Locate File CString St r = M_text + m_file.right (m_file.getlength ()-m_goto);//Set string fputs (str. GetBuffer (0), pFile); Write data to File fseek (pfile,0,seek_set);/relocate file char pchdata[1000] = {0};//define data buffer Fread (pchdata,sizeof (char), 1000,pfile );
 Read data to Buffer fclose (pFile);//close File M_file = Pchdata;
 UpdateData (FALSE);

 }
}

The

Code has a more detailed comment, which is relatively easy to understand. Readers can also further refine the program code to achieve more powerful functionality.

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.