我每个月创建的txt文件必须采用以下格式:" expense_month_year.txt"。
另外,我无法将输出文件变为txt文件
请建议
using namespace std;
int main() {
string month;
int year;
ofstream file;
cout << "Please enter the month." << endl;
getline(cin,month);
cout << "Please enter the year." << endl;
cin >> year;
//Example of txt file has to be named as follow "expenses_January_2017"
file.open(month.c_str() );
file.close();
return 0;
}
答案 0 :(得分:0)
#include <sstream>
string month
int year;
stringstream filename;
cin >> month;
cin >> year;
filename << "expenses_" << month << "_" << year;
ofstream file(filename.str());
// . . .