【发布时间】:2014-06-05 01:43:53
【问题描述】:
我有几个我不理解的错误,甚至不知道如何在互联网上进行搜索。我已经尝试过“在 C++ 函数中打开文件”以及确切的错误 0,但在前几页中没有得到太多帮助。这让我头疼了一段时间,甚至我的导师也帮不上什么忙。虽然这是他想要的方式,但不知何故。是的,这是一个家庭作业。
错误:
\driver.cpp: 在函数
void openFile(std::ifstream&, std::ofstream&)': \driver.cpp:63: error: no matching function for call tostd::basic_ifstream >::open(std::string&)' ../include/c++/3.4.2/fstream:570:注意:候选人是: void std::basic_ifstream<_chart _traits>::open(const char*, std::_Ios_Openmode) [with _CharT = char, _Traits = std::char_traits] J:\Class_Files_2013_Fall\Advanced C++\Week1\Lab_2(Letter_Counter)\driver.cpp:68: 错误:没有匹配函数调用`std::basic_ofstream >::open(std::string&)' ../include/c++/3.4.2/fstream:695:注意:候选人是: void std::basic_ofstream<_chart _traits>::open(const char*, std::_Ios_Openmode) [with _CharT = char, _Traits = std::char_traits]
所以总的来说,我有:
ifstream inFile;
//defines the file pointer for the text document
ofstream outFile;
//the file pointer for the output file
openFile(inFile, outFile);
//allow the user to specify a file for reading and outputting the stats
然后是函数:
void openFile(ifstream& inF, ofstream& outF){
// Ask the user what file to READ from
string readFile, writeFile;
cout << "Enter the name of the file you want to READ from: ";
cin >> readFile;
cout << endl;
// Open the File
inF.open(readFile);
// Ask the user what file to WRITE to
cout << "Enter the name of the file you want to WRITE to: ";
cin >> writeFile;
cout << endl;
outF.open(writeFile);
}
我也实现了:
#include <fstream>
还有:
using namespace std;
主要的东西是教练放在那里的,所以我无法更改。换句话说,我必须将文件指针传递给 openFile 函数并询问用户文件的名称。然而,我从来没有被教过如何做到这一点。一个基本的答案将不胜感激,脱离我已经在做的事情。
【问题讨论】: