How do I create a file with a user-supplied name in C++? [closed]

强颜欢笑 提交于 2019-12-31 07:44:13

问题


I want the user to be able to type some text and then the computer creates a file called what ever the text was. In C++.


回答1:


#include <cstdlib>

int main() {
    return system("read FILE && touch \"$FILE\"");
}

Note: Requires POSIX. Should be OK, practically all modern OSes are POSIX-compatible.




回答2:


Because this looks like homework, I'm not giving a complete example.

Look in:

  • #include <iostream> (Preferred) or
  • #include <cstdio> (Legacy)


来源:https://stackoverflow.com/questions/3427052/how-do-i-create-a-file-with-a-user-supplied-name-in-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!