Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


How to delete a file in C++?

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
Negima
I post too much
Reputation: 6

Joined: 22 May 2007
Posts: 2221

PostPosted: Sat Mar 29, 2008 10:35 pm    Post subject: How to delete a file in C++? Reply with quote

Can someone give me the API and header in order to delete a file in C++ at a certain directory on my computer? I looked on msnd but they only showed VB
Back to top
View user's profile Send private message Visit poster's website
Renkokuken
GO Moderator
Reputation: 4

Joined: 22 Oct 2006
Posts: 3249

PostPosted: Sat Mar 29, 2008 10:59 pm    Post subject: Reply with quote

Holy crap, there's an API called DeleteFile()
Back to top
View user's profile Send private message
Negima
I post too much
Reputation: 6

Joined: 22 May 2007
Posts: 2221

PostPosted: Sun Mar 30, 2008 1:03 am    Post subject: Reply with quote

Code:
#include <iostream>
#include <windows.h>

int main()
{
   std::cout << "Hello World\n";
   std::cout << "This is the sum of 4 and 5\n" ;
   std::cout << 5 + 4 << "\n";
   Sleep(1000);
   DeleteFile(C:\kka.txt);
   system("pause");
   Sleep(2000);
   return 0;
}


y no work
Back to top
View user's profile Send private message Visit poster's website
hcavolsdsadgadsg
I'm a spammer
Reputation: 26

Joined: 11 Jun 2007
Posts: 5801

PostPosted: Sun Mar 30, 2008 1:30 am    Post subject: Reply with quote

it takes a string, guess what you need around it. (also, extra bonus hint that you'll also need to have it work: \\)

and don't use system("pause")
Back to top
View user's profile Send private message
Negima
I post too much
Reputation: 6

Joined: 22 May 2007
Posts: 2221

PostPosted: Sun Mar 30, 2008 1:36 am    Post subject: Reply with quote

slovach wrote:
it takes a string, guess what you need around it. (also, extra bonus hint that you'll also need to have it work: \\)

and don't use system("pause")
quotes?
Back to top
View user's profile Send private message Visit poster's website
Heartless
I post too much
Reputation: 0

Joined: 03 Dec 2006
Posts: 2436

PostPosted: Sun Mar 30, 2008 5:33 am    Post subject: Reply with quote

Code:
DeleteFile("C:\\Something");

You need to use the \\ instead of just one \ and you also need to put it in quotes.

_________________
What dosen't kill you, usually does the second time.
Back to top
View user's profile Send private message
Jani
Grandmaster Cheater
Reputation: 2

Joined: 29 Dec 2006
Posts: 804

PostPosted: Sun Mar 30, 2008 6:46 am    Post subject: Reply with quote

cstdio has a function called remove..
Back to top
View user's profile Send private message
Negima
I post too much
Reputation: 6

Joined: 22 May 2007
Posts: 2221

PostPosted: Sun Mar 30, 2008 1:13 pm    Post subject: Reply with quote

Code:
#include <iostream>
#include <windows.h>

int main()
{
   std::cout << "Hello World\n";
   std::cout << "This is the sum of 4 and 5\n" ;
   std::cout << 5 + 4 << "\n";
   Sleep(1000);
   DeleteFile("C:\\kka.txt");
   system("pause");
   Sleep(2000);
   return 0;
}


why doesn't this work then
Back to top
View user's profile Send private message Visit poster's website
Renkokuken
GO Moderator
Reputation: 4

Joined: 22 Oct 2006
Posts: 3249

PostPosted: Sun Mar 30, 2008 1:20 pm    Post subject: Reply with quote

Are you running Vista? Do you have proper permissions to delete the file?
Back to top
View user's profile Send private message
hcavolsdsadgadsg
I'm a spammer
Reputation: 26

Joined: 11 Jun 2007
Posts: 5801

PostPosted: Sun Mar 30, 2008 2:11 pm    Post subject: Reply with quote

should work fine.

also:

Code:
#include <iostream>
#include <windows.h>

int main()
{
   std::cout << "Hello World\n";
   std::cout << "This is the sum of 4 and 5\n";
   std::cout << 5 + 4 << "\n";
   DeleteFile("C:\\kka.txt");
   std::cin.ignore();
   std::cin.sync();
   return 0;
}
Back to top
View user's profile Send private message
Negima
I post too much
Reputation: 6

Joined: 22 May 2007
Posts: 2221

PostPosted: Sun Mar 30, 2008 7:39 pm    Post subject: Reply with quote

Gives me this error when I try to compile

Code:
------ Build started: Project: Hello World, Configuration: Debug Win32 ------
Compiling...
Hello World.cpp
c:\users\joseph\documents\visual studio 2008\projects\hello world\hello world\hello world.cpp(10) : error C2664: 'DeleteFileW' : cannot convert parameter 1 from 'const char [11]' to 'LPCWSTR'
        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
Build log was saved at "file://c:\Users\Joseph\Documents\Visual Studio 2008\Projects\Hello World\Hello World\Debug\BuildLog.htm"
Hello World - 1 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Back to top
View user's profile Send private message Visit poster's website
lurc
Grandmaster Cheater Supreme
Reputation: 2

Joined: 13 Nov 2006
Posts: 1900

PostPosted: Sun Mar 30, 2008 8:00 pm    Post subject: Reply with quote

To Fix this you have 3 choices:

before the string put L
use _T("string") - Best Choice (include tchar.h)
use TEXT("string")

_________________
Back to top
View user's profile Send private message
hcavolsdsadgadsg
I'm a spammer
Reputation: 26

Joined: 11 Jun 2007
Posts: 5801

PostPosted: Sun Mar 30, 2008 9:04 pm    Post subject: Reply with quote

Go into your project settings and change it from unicode to multi-byte under general.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites