Welcome to collectivesolver - Programming & Software Q&A. A website you can trust. All programs tested and works. Contact: aviboots(AT)netvision.net.il
Liquid Web Managed Dedicated Server: RAID 1 SSD with 16GB of RAM minimum! 24/7 On-Site Heroic Support! Industry-Leading SLA!

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


Liquid Web Cloud VPS Hosting

8,367 questions

11,628 answers

573 users

How to read a line with specific number of characters from a text file in C++

2 Answers

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

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

int main()
{
	const int total_chars = 128;

	char line[total_chars];

	ifstream in("d:\\data.txt");

	while (in.get(line, total_chars)) {
		int count = in.gcount();
		cout << line << endl;
		cout << count << endl;
	}

	return 0;
}


/*
run:

c c++ python
12

*/

 




answered Jul 4 by avibootz
edited Jul 4 by avibootz
0 votes
#include <iostream>
#include <fstream>

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

int main()
{
	const int total_chars = 4;

	char line[total_chars];

	ifstream in("d:\\data.txt");

	while (in.get(line, total_chars)) {
		int count = in.gcount();
		cout << line << endl;
		cout << count << endl;
	}

	return 0;
}


/*
run:

c c
3
++
3
pyt
3
hon
3

*/

 




answered Jul 4 by avibootz
edited Jul 4 by avibootz
...