📄 pex12_9.cpp
字号:
#include <iostream.h>
#include <stdlib.h>
#include <fstream.h>
#pragma hdrstop
#include "array.h"
#include "strclass.h"
#include "wex12_18.h"
void main(void)
{
Array<String> A(10);
String str;
ifstream fin;
int arraySize = 10, totalLines = 0, i=0;
// open file "strfile.dat"
fin.open("strfile.dat",ios::in | ios::nocreate);
if (!fin)
{
cerr << "Could not open expfile.dat" << endl;
exit(1);
}
// read lines from "strfile.dat" until end of file
while(str.ReadString(fin,'\r') != -1)
{
// count the number of lines in the file
totalLines++;
// if the number of lines in the file exceeds the
// size of A, add 10 strings to A
if (totalLines > arraySize)
{
arraySize += 10;
A.Resize(arraySize);
}
// assign the string to A
A[i++] = str;
}
// remove any extra space in A
A.Resize(totalLines);
// for each string in A, replace all tabs by four spaces
// and print the new lines
ExpandTabs(A);
for(i=0;i < A.ListSize();i++)
cout << A[i] << endl;
}
/*
<Run>
Included is tabular data containing tabs. The data should
line up when the tabs are replaced by 4 blanks:
Number Cost Profit
1 $12,000 $2,000
2 $15,000 $3,000
3 $18,000 $3,500
4 $20,000 $4,000
5 $25,000 $5,000
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -