0

This syntax is not working in visual studio. Can someone explain why?

#include<iostream> #include <fstream> using namespace std; int main() { ofstream MyFile1("test.txt"); MyFile1 << "This is Awesome" << endl; MyFile1.close(); string line; ifstream MyFile("test.txt"); while (getline(MyFile, line)) { cout << line << endl; } MyFile.close(); } // getline is undefined identifier

13th Apr 2020, 4:30 PM
Santosh Pattnaik
Santosh Pattnaik - avatar
3 Respostas
+ 1
The problem is resolved. Actually <string> header should be included for getline() to work.
14th Apr 2020, 10:02 AM
Santosh Pattnaik
Santosh Pattnaik - avatar
+ 1
Can you please post the error message? Because it seems to work fine here.
13th Apr 2020, 4:34 PM
XXX
XXX - avatar
+ 1
getline is undefined
13th Apr 2020, 4:52 PM
Santosh Pattnaik
Santosh Pattnaik - avatar