addin files

Alright I know that a program can add files and even search in the database for matching file's but how would one make something that can add a file based on what the user puts in as followed

1
2
3
4
5
6
7
8
9
10
#include <iostream>
#inclue<string>

using namespace std; 

string ans
int main()
{
cin >> ans;
}


then after that take what ans is and make a file by what that might be.
Last edited on
This will take an input, then open a file with that name. If the file doesn't exist, it is created. If the file does exist, then its contents are replaced with nothing (for now).
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <iostream>
#include <fstream>
#include <string>

using namespace std;

int main()
{
  string filename;
  ofstream fout;
  cin >> filename;
  fout.open(filename);
  fout.close();
}
Last edited on
Alright thank you so far this is doing everything I need it too have a nice day
Topic archived. No new replies allowed.