[英]How do you create file with a variable in C++?
我想知道如何在下面的"example.txt"
放置一個變量:
ofstream file;
file.open ("example.txt");
只是在這里放一個變量:-P
如果使用std::string
則需要使用.c_str()
獲取const char*
因此您的選擇是:
const char *filename = "example.txt"
file.open(filename);
要么:
std::string filename = "example.txt"
file.open(filename.c_str());
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.