#include <iostream>
#include <fstream>
using namespace std;
#include <stdlib.h>
#include <string.h>
#define MAX_LINE_LENGTH 100
int main(int argc,char *argv[])
{
ifstream *inFilePtr;
char *strPtr,*strFileNamePtr;
strPtr=new char [MAX_LINE_LENGTH];
strFileNamePtr=new char [MAX_LINE_LENGTH];
if(argc!=2)
{
cout<<"please input the file you wanted to show:";
cin>>strFileNamePtr;
}else
strcpy(strFileNamePtr,argv[1]);
inFilePtr=new ifstream(strFileNamePtr);
if(inFilePtr==NULL)
{
cout<<"open the file:"<<strFileNamePtr<<"fail!"<<endl;
exit(1);
}
while(!inFilePtr->eof())
{
inFilePtr->getline(strPtr,MAX_LINE_LENGTH);
cout<<strPtr<<endl;
}
delete []strPtr;
delete []strFileNamePtr;
delete inFilePtr;
system("PAUSE");
return 0;
}
c++动态内存分配
最新推荐文章于 2019-10-06 09:59:31 发布