Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,926 questions

51,859 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, 2018 by avibootz

Related questions

1 answer 126 views
1 answer 99 views
1 answer 213 views
1 answer 170 views
170 views asked Jun 15, 2018 by avibootz
1 answer 237 views
...