C++, How do read in the file text? I don\'t know where to start ? success = file
ID: 3821660 • Letter: C
Question
C++, How do read in the file text? I don't know where to start ?
success = file.Open(fileName);
if (success)
{
while (true)
{
success = file.Read(fieldVector);
if (success)
{
// COMPLETE THE ROSTER LOADING HERE.
}
else
{
// COMPLETE THE END-OF-FILE HANDLING HERE.
success = true;
break;
}
}
return(success);
}
Explanation / Answer
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main () {
string content;
ifstream myfile ("sample.txt");
if (myfile.is_open())
{
while ( getline (myfile,line) )
{
cout << content << ' ';
}
myfile.close();
}
else cout << "Unable to open file";
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.