Here is source code of the C++ program which prints the lines of a file from bottom to top. The C++ program is successfully compiled and run on a Linux system. The program output is also shown below.
/*
* C++ Program to Print Lines of a File from Bottom to Top
*/
#include <iostream>
#include <fstream>
#include <vector>
int main()
{
std::string line;
std::vector<std::string> v;
std::ifstream file("main.cpp");
while (getline(file, line))
{
v.push_back(line);
}
/* Printing the lines from Bottom to Top */
for (int i = v.size() - 1; i >= 0; i--)
{
std::cout << v[i] << std::endl;
}
return 0;
}
$ g++ main.cpp $ ./a.out } } std::cout << v[i] << std::endl; { for (int i = v.size() - 1; i >= 0; i--) } v.push_back(line); { while (getline(file, line)) std::ifstream file("main.cpp"); std::vector<std::string> v; std::string line; int count = 0; { int main() #include <vector> #include <fstream> #include <iostream> */ * C++ Program to Print Lines of a File from Bottom to Top /*