How to copy data within first text file to second text file (use CStdioFile)

This is a discussion on How to copy data within first text file to second text file (use CStdioFile) within the C++ Programming forums, part of the General Programming Boards category; Now I can write data from program to text file by using WriteString() and SeekToEnd(). So I want to write ...

  1. #1
    Registered User
    Join Date
    Jan 2002
    Posts
    68

    Smile How to copy data within first text file to second text file (use CStdioFile)

    Now I can write data from program to text file by using WriteString() and SeekToEnd().
    So I want to write program to copy all data within first text file to second text file by using CStdioFile

    Do you know how to do that?
    Thank you for your answer.

    These below is some part of my program to write data from program to text file by using CStioFile

    Code:
    	outp_filename = m_uniquecodeFileName;
    
    	CStdioFile EncryptedUniqueCode;
    	CFileException FileExc;
    	UINT nOpenFlags;
    	CString szTemp, m_string;
    	nOpenFlags = CFile::modeWrite;
    	if (!EncryptedUniqueCode.Open(outp_filename, nOpenFlags, &FileExc)) {
    	FileExc.ReportError();
    	return;
    	}
    	EncryptedUniqueCode.SeekToEnd();
    
    // m_string has some value
                                                  .
                                                  .
                                                  .
    
    	EncryptedUniqueCode.WriteString(m_string+'\n');
    
    	EncryptedUniqueCode.Close();

  2. #2
    Registered User
    Join Date
    Oct 2002
    Posts
    8
    c the sample program below
    Code:
    char* pFileName = "testwrite.txt";
    char* pFileName2 = "testread.txt";
    CStdioFile f1,f2;
    f1.Open( pFileName, CFile::modeCreate
           | CFile::modeWrite | CFile::typeText ) ;
    
    f2.Open(pFileName2,CFile::modeRead);
    
    CString tempStr;
    while(f2.ReadString(tempStr))
    {
    	f1.WriteString(tempStr);
    }
    f1.Close();
    f2.Close();
    here the testread.txt should be present in the same directory as the exe.If not give the exact path.Also the exception handling is not done.


    Code tagged by Hammer

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Formatting the contents of a text file
    By dagorsul in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2008, 12:36 PM
  2. Inventory records
    By jsbeckton in forum C Programming
    Replies: 23
    Last Post: 06-28-2007, 04:14 AM
  3. Basic text file encoder
    By Abda92 in forum C Programming
    Replies: 15
    Last Post: 05-22-2007, 01:19 PM
  4. Replies: 3
    Last Post: 03-04-2005, 01:46 PM
  5. struct question
    By caduardo21 in forum Windows Programming
    Replies: 5
    Last Post: 01-31-2005, 03:49 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21