c++ - 如何制作文件名和设置扩展名

标签 c++

#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())
  {                
  }
}

我需要制作一个带有 .html 扩展名的文件,谁能告诉我怎么做或者给我写个代码?

最佳答案

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);

关于c++ - 如何制作文件名和设置扩展名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/923768/

相关文章:

c++ - 如何使用 Qt 读取我的应用程序屏幕像素数据

c++ - 使用相同的函数但不同的重载来转换 std::tr1::shared_ptr<T> 和 std::shared_ptr<T>

c++ - C可变参数宏调用另一个可变参数宏

c++ - 使用 std::map.insert ("xyz"时使用插入函数或仅使用 map[ind] ="xyz"有什么区别

c++ - 在 gcc 中将未保留的标识符作为内置宏的原因是什么?

c++ - 使用堆栈分配存储的标准兼容字符串流?

c++ - 长时间锁定互斥锁是否安全?

c++ - 名为 type 的全局变量隐藏了 Lua 中的内置 type() 函数

c++ - 使用 boost::asio::read_async 读取 Protobuf 对象

c++ - 卡在 _dl_sysinfo_int80 上的多线程应用程序