What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Skype & Technology » Tech Talk » C++ Question (Clearing a File)

C++ Question (Clearing a File)
Author: Message:
segosa
Community's Choice
*****


Posts: 1407
Reputation: 92
Joined: Feb 2003
RE: C++ Question (Clearing a File)
It's simple. Do what Ash_ said and look up CreateFile().

http://msdn.microsoft.com/library/default.asp?url...ase/createfile.asp

I know it's long, but if you want to be a programmer you have to be capable of reading large amounts of text.

Notice that dwCreationDisposition says this:

code:
[in] Action to take on files that exist, and which action to take when files do not exist. For more information about this parameter, see the Remarks section. This parameter must be one of the following values.

CREATE_ALWAYS

Creates a new file. If the file exists, the function overwrites the file, clears the existing attributes, combines the specified file attributes and flags with FILE_ATTRIBUTE_ARCHIVE, but does not set the security descriptor specified by the SECURITY_ATTRIBUTES structure.


So that's all you need to do, use CreateFile(), then CloseHandle().

And since CreateFile is like this,
code:
HANDLE CreateFile(
  LPCTSTR lpFileName,
  DWORD dwDesiredAccess,
  DWORD dwShareMode,
  LPSECURITY_ATTRIBUTES lpSecurityAttributes,
  DWORD dwCreationDisposition,
  DWORD dwFlagsAndAttributes,
  HANDLE hTemplateFile
);


going through each parameter on MSDN you'd end up with

HANDLE hFile=CreateFile("filename.txt", GENERIC_READ, NULL, NULL, CREATE_ALWAYS, NULL, NULL);
CloseHandle(hFile);

That's it. And if you can do linked lists, I'm sure you could have done this. :P

This post was edited on 03-30-2005 at 06:18 AM by segosa.
The previous sentence is false. The following sentence is true.
03-30-2005 05:31 AM
Profile PM Find Quote Report
« Next Oldest Return to Top Next Newest »

Messages In This Thread
C++ Question (Clearing a File) - by Maniac on 03-29-2005 at 11:36 PM
RE: C++ Question (Clearing a File) - by Ash_ on 03-30-2005 at 12:20 AM
RE: C++ Question (Clearing a File) - by Maniac on 03-30-2005 at 12:28 AM
RE: C++ Question (Clearing a File) - by segosa on 03-30-2005 at 05:31 AM


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On