Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

vcgames

Problem on file read and write?

This topic is 5560 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I want to read a html file into the memory and write it to another file using Archive class.But It dosen''t work well.These are my codes.
	static char szFilter[] = "Html files(*.htm) |*.htm||";
	CFileDialog linkfile(TRUE, NULL, NULL,  OFN_HIDEREADONLY |
		 OFN_ALLOWMULTISELECT |OFN_OVERWRITEPROMPT, szFilter, this);
	
	CString str("", 10000);
	linkfile.m_ofn.lpstrFile = str.GetBuffer(10000);
	str.ReleaseBuffer();

	if (linkfile.DoModal() == IDOK) // open file dialog

	{
		static char szSaveFilter[] = "Html files(*.htm)|*.htm|Word files(*.doc)|*.doc|Text files(*.txt)|*.txt||";
		CFileDialog savefile(FALSE, NULL, NULL, OFN_HIDEREADONLY |
		OFN_OVERWRITEPROMPT, szSaveFilter, this);

		if (savefile.DoModal() == IDOK) // save file dialog

		{
			CString saveFileName = savefile.GetFileName();
			CFile save(saveFileName, CFile::modeWrite | CFile::modeCreate);

			if (save)
			{
				CArchive arWrite(&save, CArchive::store);
				CString strTemp;
				POSITION m_Pos = linkfile.GetStartPosition();
				
				CString pathName("", 255);
				
				while (m_Pos != NULL)
				{
					pathName = linkfile.GetNextPathName(m_Pos);
					if (pathName)
					{
						CFile read(pathName, CFile::modeRead);
						if (read)
						{
							CArchive arRead(&read, CArchive::load); 
							arRead >> strTemp; // read file to strTemp

							arWrite << strTemp; // write to another file


							arRead.Close();
						}
					}
				}
				arWrite.Close();
			}
		}
	}
}
I don''t know what is wrong! Would you please give me some advice? Thanks!

Share this post


Link to post
Share on other sites
Advertisement
I honestly don't think archives are supposed to be read that way. They use special teminating characters to mark where to start/stop reading.

Try using the fstream class or CFile.

[edited by - natasdm on September 22, 2003 7:52:10 AM] -> stupid tags

[edited by - natasdm on September 22, 2003 7:53:26 AM]

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!