我不知道我的代码有什么问题。我正在尝试从控制台获取两个文件的文件路径,然后我用这些文件初始化一些 fstream 对象,ios::in | ios::out
其中一个,另外一个ios::binary
。
以下是我的代码的重要部分:
// Function prototypes
void INPUT_DATA(fstream);
void INPUT_TARGETS(fstream);
int main()
{
// Ask the user to specify file paths
string dataFilePath;
string targetsFilePath;
cout << "Please enter the file paths for the storage files:" << endl
<< "Data File: ";
getline(cin, dataFilePath); // Uses getline() to allow file paths with spaces
cout << "Targets File: ";
getline(cin, targetsFilePath);
// Open the data file
fstream dataFile;
dataFile.open(dataFilePath, ios::in | ios::out | ios::binary);
// Open the targets file
fstream targetsFile;
targetsFile.open(targetsFilePath, ios::in | ios::out);
// Input division data into a binary file, passing the proper fstream object
INPUT_DATA(dataFile);
// Input search targets into a text file
INPUT_TARGETS(targetsFile);
...
}
// Reads division names, quarters, and corresponding sales data, and writes them to a binary file
void INPUT_DATA(fstream dataFile)
{
cout << "Enter division name: ";
...
dataFile << divisionName << endl;
...
}
// Reads division names and quarters to search for, and writes them to a file
void INPUT_TARGETS(fstream targetsFile)
{
cout << "\nPlease input the search targets (or \"exit\"):";
...
targetsFile.write( ... );
...
}
然而,Visual Studio 在INPUT_DATA(dataFile);
和INPUT_TARGETS(targetsFile);
部分对我大喊大叫,说:
function "std::basic_fstream<_Elem, _Traits>::basic_fstream(const std::basic_fstream<_Elem, _Traits>::_Myt &) [with _Elem=char, _Traits=std::char_traits<char>]" (declared at line 1244 of "c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\fstream") cannot be referenced -- it is a deleted function
我翻遍了头文件,直到找到第 1244 行:
basic_fstream(const _Myt&) = delete;
我不知道为什么会这样。我对 C++ 还是很陌生,我可能刚刚做了一些愚蠢的事情,但是有人可以帮忙吗?
编辑:澄清标题