can you use File I/O to create files anywhere like C:\blah? cuz when I try and do that with C++ Builder 6, it doesn't work
can you use File I/O to create files anywhere like C:\blah? cuz when I try and do that with C++ Builder 6, it doesn't work
Yes all you have to do is eg.
and you should be good to goCode:ofstream file("c:\\Loser.txt");
Woop?
thanks so much!!!!!!!!!!!!!
Your welcome so much and welcome to the boards
Woop?
thanks for the help but I have another question. how can you delete a file? and if an error comes up for deleting (if it ever does), is there a way to ignore this error, but store this error in a variable or something?
Last edited by cude87; 07-10-2004 at 10:08 PM.
Try this method
[edit] forgot the <io.h> and the file.close() [/edit]Code:#include <iostream> #include <fstream> #include <io.h>//Need for the _unlink function :) using namespace std; int main() { ofstream file("File.txt"); file.close(); _unlink("File.txt"); return 0; }
Last edited by prog-bman; 07-10-2004 at 10:20 PM.
Woop?
thanks for the help but I could've done that with basic ofstream. that just empty's the file. I wanna know how to completely delete it. and do you know how to do shutdown, log off, restart, and quick shutdown (insecure) functions?
I'm trying to build a shutdown program which recongnize keystrokes and does the desired function. like ctrl + F1 is shutdown, ctrl + alt + F1 is emergency instant shutdown, etc. the delete and writing is for the settings file. I did the key part. I just need the functions and delete function.
EDIT: nvm, the delete function works perfectly. thanks, but I still need to know the other functions :-/
I think I found something.....is this true? :
option is:Code:BOOL ExitWindowEx(UINT option here, DWORD dwRes)
EWX_FORCE
EWX_LOGOFF
EWX_POWEROFF
EWX_REBOOT
EWX_SHUTDOWN
does this work? if so, which one is emergency shutdown? FORCE, POWEROFF?
You would use EWX_FORCE and EWX_POWEROFF most likely for an emergency shutdown.
Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah
You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie
I think I need to include a file. which one? windows.h?
you can use too:
just check you use the "/" not the "\", because in a c/c++ is a special char(used to new line)Code:ofstrem obj("c:/some_dir/some_dir/etc", ios::out);
I know about that. I want to know how to shutdown, logoff, etc. I think the functions there work, but I don't know which include file I need or something....
>ofstream file("c:\\Loser.txt");
It couldn't hurt to explain why this is so, prog-bman. cude87: The reason you need to double the backslashes is because string literals in C++ support escape characters, where any character or special sequence preceded by a backslash is treated specially. A good example is '\n'. Instead of meaing '\' and 'n', this escape character becomes a newline. If you say "c:\blah.txt" then C++ will think that you're trying to use the escape character '\b'. In this case you're lucky because that's a real escape character that stands for a backspace. If it weren't legal then you would be invoking undefined behavior. The reason '\\' works is because if you escape the backslash character, the result is a backslash, which is what you want.
Some people may recommend that you use a forward slash instead to avoid escaping the next character, but that's not portable and won't work everywhere. If you can avoid non-portable constructs (like now because it's easy) then you should.
>_unlink("File.txt");
Not portable, nor is <io.h>. C++ supports a standard function called remove that does what the OP wants. It's found in <cstdio>.
My best code is written with the delete key.
oh i thought _unlink wasn't portable but i wasn't sure. and thanks for the remove info
Woop?