gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-04 14:59:12 25 4
gpt4 key购买 nike

#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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com