0

ok, i need small help, to create/open a file with specific name, in order to make it clear here's a small function from my program

void CreateNew () 
{
     string fileName = "helpme.txt"; //==>>> my problem!!
     ofstream DataFile;
    DataFile.open(fileName, ios::out | ios::app); // string fileName == filename 
     if (DataFile.is_open())
     {
                          cout<<"Yeah, created"<<endl;
                          cout<<"Filename: "<<fileName<<endl;
     }
     else
     {
         cout<<"Call cops!"<<endl;
     }
     DataFile.close(); //flush 
}

Thank you!

2
Contributors
1
Reply
2
Views
10 Years
Discussion Span
Last Post by Narue
0

>DataFile.open(fileName, ios::out | ios::app);

DataFile.open(fileName.c_str(), ios::out | ios::app);

The open member function takes a C-style string.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.