Welcome to collectivesolver - Programming & Software Q&A. A website you can trust. All programs tested and works. Contact: aviboots(AT)netvision.net.il
GreenGeeks Web Hosting - Faster, Scalable & Eco-Friendly

BlueHost Web Hosting

Ecommerce Software - Best Ecommerce Platform Made for You - Free Trial

Ecommerce Software - Best Ecommerce Platform Made for You - Free Trial

getflywheel wordpress hosting


Distribute your Resume to 500+ Job Boards & Recruiters


7,930 questions

11,045 answers

573 users

How to read text file backwards in C++

1 Answer

0 votes
#include <iostream>
#include <fstream>

using std::cout;
using std::endl;
using std::ifstream;

int main()
{
	ifstream ifs("d:\\data.txt");

	if (!ifs) {
		cout << "Error open file" << endl;
		return 1;
	}

	char ch;
	long size;
	ifs.seekg(0, std::ios::end);
	size = (long)ifs.tellg(); 
	size--;

	for (int i = size; i >= 0; i--) {
		ifs.seekg(i, std::ios::beg);
		ifs.get(ch);
		cout << ch;
	}
	cout << endl;

	ifs.close();

	return 0;
}


/*
run:

nohtyp ++c c

*/

 




answered Jul 3 by avibootz
...