首先,我为我的糟糕英语感到抱歉。如何打印从不同功能的文本文件中读取的数据
我想问的是如何打印从不同功能的文本文件中读取的数据。
load()
函数定义如下。
void Picture::load(string filename) throw(string)
{
int x,y;
string line;
fstream infile(filename.c_str(), fstream::in);
if (infile.is_open())
{
if (!getline(infile, line))
throw string("Unable to read the first line.");
istringstream iss(line);
if (!(iss >> height >> width))
throw string("First line does not consist of two integers.");
picture = new char*[width];
for (x=0; x<width; x++)
picture[x] = new char[height];
for (y=0; y<height; y++)
{
getline(infile,line);
if (line.length() < width)
throw string("Line "+convertInt(y+1)+" in picture has an incorrect width.");
else
for (x=0; x<width; x++)
set(x,y,line[x]);
}
infile.close();
}
else throw string("Unable to open file");
}
void Picture::print()
{
// This function will print the data read on load function
}
如何将这两个函数关联起来以便加载和打印?
对不起,如果这个问题之前已经问过。
我有一个私有成员'字符** picture'。你可以参考我最近编辑的关于'load()'函数的问题吗? – user3538277