Hi all
I want to know that in C++ is there any process for create a file with user defined name
For example :
User give me a name "abc". Now I need to made a text file with name "abc.txt" and also want to save that file in my computer so that i can store data in that text file.
If there has any process for that please tell me what it is.
bro i don't need to show the file name only i also need to create file with that name and save that file in my computer
Is there any process for that??
include <string>
#include <iostream>
#include <fstream>
int main()
{
std::string name;
std::cout << "Enter name: ";
std::getline(std::cin, name);
name += ".txt";
std::ofstream ofs(name);
if (!ofs.is_open()) {
std::cout << "Cannot open file for output\n";
return 1;
}
// output data to ofs stream here as needed
ofs.close();
}