麻烦哪位高手帮我看一下哪错了
阳心扬涵 2012-05-09 06:16:26
#include <fstream>
#include <iostream>
#include <string>
using namespace std;
void main(int argc, char *argv[])
{
ofstream outfilea;
outfilea.open(argv[1],ios::out|ios::app);//|ios::trunc
if(!outfilea)
{
cerr<<"open error!"<<endl;
//abort();//退出程序
}
char str[140];
int len=strlen(str);
cout<<"Enter the data:(139)"<<endl;
getchar(); //提取前一个换行符
cin.getline(str,140,'\n');
outfilea.write((char*)&str,len);
outfilea.close();
ifstream infilea;
infilea.open(argv[1],ios::in);
if(!infilea)
{
cerr<<"open error!"<<endl;
abort();//退出程序
}
streampos filelengtha;
infilea.seekg(0,ios::end);
filelengtha=infilea.tellg();
char *buffer;
infilea.read(buffer,filelengtha);
//infile>>endl;
infilea.close();
ofstream outfileb(argv[2],ios::out|ios::app);
if(!outfileb)
{
cerr<<"open error!"<<endl;
abort();//退出程序
}
outfileb.write(buffer,len);
outfileb.close();
ifstream infileb(argv[2],ios::in|ios::binary);
streampos filelengthb;
infileb.seekg(0,ios::end);
filelengthb=infileb.tellg();
if(!infileb)
{
cerr<<"open error!"<<endl;
abort();//退出程序
}
infileb.read(buffer,filelengthb);//
cout<<buffer<<endl;
infileb.close();
cout<<"************************************************"<<endl;
}
编写程序lab6_1.cpp,编写程序,用二进制方式读写指定的文件a.bin,在每一行前加行号,写入另一个二进制文件b.bin中,
从b.bin中读取数据输出到屏幕使用void main(int argc, char*argv[])函数中的参数传递操作的文件名,定义ofstream的对象对文件进行操作,使用read()和write()成员函数读入数据,
使用输出流对象输出数据到文件和屏幕。