How do I create a file with a user-supplied name i

2020-05-10 05:31发布

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

2条回答
Summer. ? 凉城
2楼-- · 2020-05-10 06:11

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

Look in:

  • #include <iostream> (Preferred) or
  • #include <cstdio> (Legacy)
查看更多
你好瞎i
3楼-- · 2020-05-10 06:17
#include <cstdlib>

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

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

查看更多
登录 后发表回答