从文件流中读取数据
#include "iostream"
#include "string"
#include "fstream"
using namespace std;
class Text
{
public:
Text();
Text(string str);
~Text();
string contents();
private:
string str1;
};
Text::Text()
{
str1="hello";
}
Text::Text(string str)
{
ifstream input("str",ios_base::binary);
if(input.eof())
{
input.read(( char*)&str1, sizeof(str1)) ;
}
input.close();
}
string Text::contents ()
{
return str1;
}
Text::~Text ()
{
cout<<"Reference";
}
int main()
{
string str3;
Text text("hello.txt") ;
str3=text.contents ();
cout<<str3;
return 0;
}
为什么我得不到我要的结果呀 hello.txt 中存放的是hello