#include<iostream>//设计一个测试seekg()的程序
#include<fstream>
#include<string>
class Chih
{
std::ifstream in;
std::ofstream out;
int a;
std::string file;
std::string file1;
public:
Chih();
~Chih();
void Check();
};
Chih::Chih()
{
std::cout << "Write your file name: ";
std::cin >> file;
in.open(file, std::ios::binary);
if (!in)
{
std::cout << "failed to open your file -o-!" << std::endl;
exit(1);
}
std::cout << "Input your storage file name: ";
std::cin >> file1;
out.open(file1, std::ios::binary);
if (!out)
{
std::cout << "failed to open storage file 0-0!";
exit(1);
}
}
Chih::~Chih()
{
in.close();
out.close();
}
void Chih::Check()
{
char buf[1000];
in.seekg(2, std::ios::beg);//seekg难道也是ifstream的成员函数吗?
in.read((char*)&buf, sizeof(buf)/5);
//out.seekg(20,std::ios::cur);//seekg()是类istream和ostream的成员函数
out.write((char*)&buf, sizeof(buf)/5);
}
int main()
{
Chih du;
du.Check();
return 0;
}
第二个注释是编这个程序的时候遇到的另一个问题。