【发布时间】:2014-04-01 16:53:17
【问题描述】:
好吧,在程序创建一个文件夹之后,我会在该文件夹中放置一个文件,但我希望该文件是用户输入的名称,所以我将如何做到这一点,因为我现在已经设置了所有它的作用是通过 Exampleuser 输入的名称创建一个文件,然后输入“/two”只是通过两个名称创建一个文件。
#include <iostream>
#include <direct.h>
#include <string>
#include <fstream>
using namespace std;
string newFolder = "Example";
string test ;
string two;
int main()
{
_mkdir((newFolder.c_str()));
getline(cin,test);
two = test;
fstream inout;
inout.open(newFolder + two,ios::out);
inout << " This is a test";
inout.close();
return 0;
}
【问题讨论】:
-
什么是操作系统?
-
文件夹名和文件名之间可能需要一个分隔符。例如,在 Linux 上为:
new_folder + "/" + two. -
好的,感谢“\\”为我工作,因为我在 Windows 上