例如,我正在尝试从文件中读取时间 (12:00 A) 我需要阅读所有三个部分。这是我的。
#include <iostream>
#include <fstream>
#include <stdio.h>
using namespace std;
int main()
{
string name, filename;
ifstream inputFile;
cout << "What is the name of the file to be provessed ";
cin >> filename;
inputFile.open(filename.c_str());
getline(inputFile, name);
fscanf (inputFile, "%d:%d %c", &startH, &startM, &startAP);
fscanf (inputFile, "%d:%d %c", &endH, &endM, &endAP);
inputFile >> payRate;
我从标题中得到错误,我不确定我做错了什么。
最佳答案
函数fscanf
是 header 中声明的标准 C 函数 <cstdio>
以下面的方式(我将展示如何在 C 中的 header <stdio.h>
中声明该函数。事实上除了关键字 restrict 在 C++ 中使用相同的声明)
int fscanf(FILE * restrict stream,
const char * restrict format, ...);
如您所见,没有 std::ifstream
类型的参数
因此编译器发出错误,因为它无法找到名称为 fscanf 且第一个参数类型为 std::ifstream 的函数,同时它无法隐式转换类型为 std::ifstream
的对象。指向 FILE *
类型的指针
不应将 C++ 流函数与 C 流函数混合使用。
关于c++ - 没有匹配函数调用 'fscanf',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22290546/