我希望用戶要做的是在testquote中輸入文件名,然後爲我的程序在最後添加.txt以將文件保存爲.txt,這樣我就可以將多個引號保存到計算機中而不會寫入。這是我到目前爲止有:保存txt文件作爲變量的名稱
cout << "What would you like to save the quotation as? (Maybe using your last name) " << endl;
cin >> nameOfFile;
ofstream outfile; // Opens file in write mode
outfile.open(nameOfFile)<<(".txt"); // Opens the quotations file
//Lawn
outfile << "The total lawn area is " << lawnArea << " square meters" << endl; // Writes users data into the file
outfile << "The total cost for the lawn is £" << (lawnArea * lawnCost) << endl; // Writes users data into the file
你有什麼問題? – khajvah
'nameOfFile'是一個'std :: string'嗎? –
'outfile.open(nameOfFile)<<(「。txt」); //打開引用文件'不,它絕對不會!首先構造字符串(例如使用'+'運算符),然後用構造的字符串打開文件。 –