如何在 C++ 中创建具有用户提供的名称的文件?

发布于 2024-09-13 18:45:42 字数 49 浏览 1 评论 0原文

我希望用户能够输入一些文本,然后计算机创建一个名为“文本是什么”的文件。在C++中。

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++.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

断桥再见 2024-09-20 18:45:42
#include <cstdlib>

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

注意:需要 POSIX。应该没问题,几乎所有现代操作系统都兼容 POSIX。

#include <cstdlib>

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

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

执着的年纪 2024-09-20 18:45:42

因为这看起来像家庭作业,所以我没有给出完整的例子。

查看:

  • #include(首选)或
  • #include(旧版)

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

Look in:

  • #include <iostream> (Preferred) or
  • #include <cstdio> (Legacy)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文