Hi,
I need to create a new file and then name it a number.
I would be using ofstream()
Thanks
Hi,
I need to create a new file and then name it a number.
I would be using ofstream()
Thanks
Okay,
This is what I used that works:
#include <iostream.h>
#include <stdlib.h>
#include <fstream.h>
#include <iostream.h>
#include <windows.h>
#include <conio.h>
int main()
{
char str[30];
cin>>str;
strcat(str,".txt");
ofstream a_file(str);
a_file << "sadfasf";
return 0;
}
Now, what do I do if I want to delete the file?
Thanks
a_file.close();
-Prelude
My best code is written with the delete key.
Jesus... that is a lot of includes...
Code:#include <iostream> // for standard i/o #include <fstream> // for file i/o #include <stdlib> // for system call using namespace std; int main() { ofstream outs; char answer = 'n'; outs.open("file.txt"); // open/create file outs << "This is some text in a file"; outs.close(); //close file cout << "do you want to delete file (y/n):"; cin >> answer; if ((answer == 'y')||(answer == 'Y')) system ("del file.txt"); // delete file return 0; } // end main
Blue