This is my code to create a new file below.
The main problem is that the program does not halt for entering file name
and also the program creates a file .txt and doesn't save anything in it.
Please Help
int newfile()
{
system("cls");
cout <<"\t\t-------------------------------------" <<endl;
cout <<"\t\t| NEW FILE |" <<endl;
cout <<"\t\t-------------------------------------" <<endl;
cout <<"\t\t|Enter New File Name| "; getline(cin,createfile);
cout <<"\t\t----------" <<endl;
string text;
int nl = 0;
cout<<"Press enter twice in a row to quit: ";
while (nl < 2 && getline(cin, text))
{
if (text.empty())
{
++nl;
}
}
if(! outfile)
{
cout <<"error writing to file" <<endl;
return -1;
}
outfile.open((createfile+".txt").c_str());
outfile << text <<endl;
outfile.close();
}
Any help appreciated.
Anurag.