0
这是包含我无法修复的错误的代码。 我的代码打开文本文件似乎是错误的,但我试图看看它有什么问题,但无法找到它。我有类似的程序,这个代码可以工作,但这不是。错误:没有用于调用ifstream :: open(string)的匹配函数
错误: 用于调用 '的std :: basic_ifstream ::开(STD :: __ cxx11 :: string的&)' 不匹配函数 FILE.open(文件名)< ---
#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;
#include "nameSort.h"
size_t readNames(string filename, string surnames[], string firstnames[])
{
//initialize size top 0
size_t SIZE = 0;
//open file for input
ifstream FILE;
FILE.open(filename);//(This is where the error is)
//check if file exists
if(!FILE)
{
cout << "Error! No such file!\n";
return 0;
}
else
{
//read file data to arrays
while(!FILE.eof())
{
FILE >> firstnames[SIZE] >> surnames[SIZE];
SIZE++;
}//end while
}//end if
FILE.close();
return size;
}
您是否正在编译至少启用C++ 11? –
它在我插入文本文件名称而不是变量时起作用,是否有人知道为什么我会在变量中出现错误? –
尝试'FILE.open(filename.c_str());',但更好地启用C++ 11 – user463035818