tags:

views:

64

answers:

3
#include <iostream>
#include <fstream>

using namespace std;
int main()
{
  string name;
  cout<<"What would you like new html file to be named?"<<endl;
  getline(cin,name);
  cout<<"Creating New Html File...Moment."<<endl;
  ofstream myfile (name);
  if(myfile.is_open())
  {                
  }
}

I need to make myfile with a .html extension can somebody tell me how or write me a code?

+7  A: 
string name;
cout<<"What would you like new html file to be named?"<<endl;
getline(cin,name);
cout<<"Creating New Html File...Moment."<<endl;

name+=".html"; // the crucial ommision?

ofstream myfile (name);
1800 INFORMATION
Probably sensible to check that the given name does not itself end with ".html" so you do not create "file.html.html".
Jonathan Leffler
+1  A: 

You simply need to add .html to the end of the file name:

name.append(".html");
Zifre
A: 

Do you want to take into account the possibility that the filename entered by the user already ends in ".html" ? In that case, you can get the suffix with name.substr(name.size()-5) - after you've checked that there are at least 6 characters in name, of course.

MSalters