C++,无法打开源文件 "ifstream" Visual Studio
C++, cannot open source file "ifstream" Visual Studio
我得到两种语法?即使项目构建成功,也会出现错误。在我评论过的以下位置,我的代码的某些部分在 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
定义在header<fstream>
中。没有标准header<ifstream>
.
C++ifstream
以一个c-string
作为打开文件名的参数。只需将 ifstream dicFile(name);
中的 name
更改为 ifstream dicFile(name.c_str());
您还包含了一个名为 ifstream
的库,该库不存在。 ifstream
对象在 fstream
库中。
我得到两种语法?即使项目构建成功,也会出现错误。在我评论过的以下位置,我的代码的某些部分在 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
定义在header<fstream>
中。没有标准header<ifstream>
.
C++ifstream
以一个c-string
作为打开文件名的参数。只需将 ifstream dicFile(name);
中的 name
更改为 ifstream dicFile(name.c_str());
您还包含了一个名为 ifstream
的库,该库不存在。 ifstream
对象在 fstream
库中。