【发布时间】:2020-02-02 17:44:04
【问题描述】:
我正在尝试使用 Visual Studio 2019 的内置编译器读取 C++ 中的文件。按照我找到的一些示例,我尝试这样做:
#include <iostream>
using namespace std;
int main() {
ifstream file("test.txt");
string input = "";
while (file >> input) {
std::cout << input;
}
std::cout << "Hello World!\n";
}
但是,在编译 Visual Studio 时显示错误 incomplete type is not allowed。输出窗口显示error C2079: 'file' uses undefined class 'std::basic_ifstream<char,std::char_traits<char>>'。
像这样关注this thread:
ifstream file;
file.open("test.txt");
给了我同样的错误。
- 错误是什么意思?
- 如何解决?
【问题讨论】:
标签: c++ input io header-files