关于fstream的用法,求解
#include <fstream>#include <string>
#include <iostream>
using namespace std;
string readstr(string s)
{
int i=0;
string a,b;
const char* str=s.data();
ifstream fin( str );
while(fin>>a)
{
cout<<a;//这里就可以输出字符
i++;
}
cout<<a;//这里就不能输出a了
return a;//返回值会为空
fin.close();
}
main()
{
string filename1,sequence1;
cout<<"please input the filename about string:"<<endl;
cin>>filename1;
filename1=filename1+".txt";
sequence1=readstr(filename1);
cout<<sequence1<<endl;
return 0;
}
页:
[1]