ifstream fin;
char* t1;
string t2;
cout<<"请输入文件名:";
cin>>t2;
const int len=t2.length();
t1=new char[len+1];
strcpy(t1,t2.c_str());
fin.open(t1,ios::in);
char temp[100]={0};
fin.getline(temp,sizeof(temp),10);//长度是10,10在ASCII中代表换行符
cout<<temp<<endl;
sample.txt文件内容:

运行结果

把sample.txt文件内容改为

运行结果

真心搞不懂了- -求巨巨们帮忙
