[英]C++, cannot open source file “ifstream” Visual Studio
I am getting two syntax? 我得到两种语法? errors even though the project builds successfully. 即使项目成功构建,也会出现错误。 Certain parts of my code are highlighted as red in Visual Studio in the following locations that I have commented at: 我在以下位置中的代码在Visual Studio中将代码的某些部分突出显示为红色:
#include <vector>
#include <string>
#include <iostream>
#include <ifstream> //include is highlighted// Error: cannot open source file "ifstream"
using namespace std;
class DictionarySorter{
public:
DictionarySorter(){
}
void readDic(string name){
ifstream dicFile (name); //dicFile is highlighted here// Error: incomplete type is not allowed
}
private:
vector<string> v;
};
std::ifstream
is defined in the header <fstream>
. std::ifstream
在头文件<fstream>
定义。 There is no standard header <ifstream>
. 没有标准头文件<ifstream>
。
The C++ ifstream
takes a c-string
as the parameter for the opening of a file name. C ++ ifstream
将c-string
作为打开文件名的参数。 Simply change the name
in ifstream dicFile(name);
只需在ifstream dicFile(name);
更改name
ifstream dicFile(name);
to ifstream dicFile(name.c_str());
到ifstream dicFile(name.c_str());
You're also including a library called ifstream
which doesn't exist. 您还将包括一个不存在的名为ifstream
的库。 The ifstream
object is within the fstream
library. ifstream
对象在fstream
库中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.