C++ 对';fscanf';

C++ 对';fscanf';,c++,scanf,C++,Scanf,我试图从文件中读取时间,例如(12:00A) 我需要把这三部分都读一遍。这是我的 #include <iostream> #include <fstream> #include <stdio.h> using namespace std; int main() { string name, filename; ifstream inputFile; cout << "What is the name of the fil

我试图从文件中读取时间,例如(12:00A) 我需要把这三部分都读一遍。这是我的

#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;
#包括
#包括
#包括
使用名称空间std;
int main()
{
字符串名称、文件名;
ifstream输入文件;
cout>文件名;
open(filename.c_str());
getline(输入文件,名称);
fscanf(输入文件,“%d:%d%c”、&startH、&startM、&startAP);
fscanf(输入文件,“%d:%d%c”、&endH、&endM、&endAP);
输入文件>>支付率;

我从标题中得到了错误,我不确定我做错了什么。

函数
fscanf
是一个标准的C函数,它在header
中以以下方式声明(我将展示如何在header
中在C中声明函数。事实上,除了关键字restrict之外,在C++中使用了相同的声明)

如您所见,没有类型为
std::ifstream

因此,编译器会发出错误,因为它找不到名为fscanf的函数,该函数的第一个参数类型为std::ifstream,同时它不能隐式地将类型为
std::ifstream
的对象转换为类型为
FILE*


不应该将C++流函数与C流函数混合。请将错误信息显示给我们。不要把对象作为输入机制。它使用<代码>文件*/COD>。停止混合C和C++。@ WoZoCurg,因为某些原因,我也不喜欢它们……- @ PasZrtoPithHe。与你所带的人跳舞。(我父亲十几岁时的一句老话)=P@WhozCraig-)非常正确,特别是在这种情况下,你会建议我从文件中读取一段时间吗?@ USER330992查看C++本地化库或自己编写函数。

int fscanf(FILE * restrict stream,
const char * restrict format, ...);