⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pex8_2.cpp

📁 数据结构C++代码,经典代码,受益多多,希望大家多多支持
💻 CPP
字号:
#include <iostream.h>
#include <iomanip.h>
#pragma hdrstop

#include "wex8_7.h"

// print the file represented by ReadFile object f with
// line numbers
void LineNum(ReadFile& f)
{
	// line number counter
	int linenum = 1;
	
	// left justify output
	cout.setf(ios::left);
	
	// read lines until end of file
	while(f.Read() != 0)
	{
		// output line number left justified
		cout << setw(5) << linenum << " ";
		// output current line followed by end of line
		f.PrintBuffer();
		cout << endl;
		// increment the line number counter
		linenum++;
	}
	
	// reset output justification to right
	cout.setf(ios::right);
}

void main (void)
{
	char fname[30];

	cout << "Enter the file name: ";
	cin >> fname;
	
	// declare an ReadFile object that reads fname and has a
	// 256 character buffer
	ReadFile f(fname,256);

	// print file fname with line numbers
	LineNum(f);
}
/*
<Run>

<file "pex8_2.dat>

This text file tests the
construction of the class ReadFile
in Written Exercise 8.7

Enter the file name: pex8_2.dat
1     This text file tests the
2     construction of the class ReadFile
3     in Written Exercise 8.7
*/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -