关于我之前在这里发布的一个老问题,我询问了我在 FileOpen 函数上遇到的一个问题。这个新问题与第二部分有关:FileReader。
我进行了更改,但仍然存在编译器错误。
这是麻烦的代码:
FILE *FileReader(FILE *fname){
ifstream inputFile;
inputFile.open(fname);
if(inputFile){
string line = "";
//int num_chars;
while(getline(inputFile, line)){
//num_chars = strlen(text) + 1;
//line = (string *)malloc(sizeof(string)*num_chars)
int i = 0;
if(i <= 3 ){
storString[i] = line;
storage[i] = atoi(storString[i].c_str());
i++;
}
else{
string firstTwo = line.substr(0,1);
const int hex = atoi(firstTwo.c_str());
setOperations(hex);
string commandOne = firstTwo.substr(0,0); //first part of command
string commandTwo = firstTwo.substr(1,1); //second part of command and n-i flags
string restFlags = line.substr(2,2); //xbpe flags
rest = line.substr(3);
int disp = atoi(rest.c_str());
if(format == "fmt2"){
string rOne = line.substr(2,2);
int registerOne = atoi(rOne.c_str());
string rTwo = line.substr(3,3);
int registerTwo = atoi(rTwo.c_str());
registerOperation(hex, registerOne, registerTwo);
break;
}
setFlags(commandTwo, restFlags, disp);
}
}
}
}
输出以下错误:
a1/a1.cpp:在函数中FILE* FileReader(FILE*)
:
a1/a1.cpp:338:错误:没有匹配函数调用std::basic_ifstream<char, std::char_traits<char> >::open(FILE*&)
/opt/local/bin/../lib/gcc/sparc-sun-solaris2.10/3.4.6 /../../../../include/c++/3.4.6/fstream:570:注意:候选人是:void std::basic_ifstream<_CharT, _Traits>::open(con
st char*, std::_Ios_Openmode)
[with _CharT = char, _Traits = std::char_traits]
编辑:
请参阅那些注释掉的行。我也尝试了这些,但不知道如何实现它们。谁能帮我?