Reputation: 1055
I am trying to read a file in C++, using the built in compiler of Visual Studio 2019. Following some examples I found, I try this:
#include <iostream>
using namespace std;
int main() {
ifstream file("test.txt");
string input = "";
while (file >> input) {
std::cout << input;
}
std::cout << "Hello World!\n";
}
However, while compiling Visual Studio shows the error incomplete type is not allowed
. The output window shows error C2079: 'file' uses undefined class 'std::basic_ifstream<char,std::char_traits<char>>'
.
Following this thread like so:
ifstream file;
file.open("test.txt");
gives me the same error.
Upvotes: 2
Views: 1455
Reputation: 311078
You need to include additionally two headers
#include <fstream>
#include <string>
Pay attention to that instead of this declaration
string input = "";
you could just write
string input;
Upvotes: 4