Answer to Question #72073 in C++ for Dhvani

Question #72073
Write a C++ code which reads the contents of a text file “first_file.txt”
1
Expert's answer
2017-12-22T04:43:16-0500
/*
* main.cpp
*
*/

#include <iostream>
#include <fstream>
#include <string>

int main()
{
std::ifstream in("first_file.txt");
std::string line;

if (!in) {
std::cout << "File not found!\n";
return 0;
}

while (std::getline(in, line)) {
std::cout << line << std::endl;
}

return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS