兩種方式
# include<sstream>
# include<fstream>
# include<string>
int main()
{
ifstream in("input.txt");
stringstream temp;
temp<<in.rdbuf();
string text = temp.str();//將字符串流轉化爲字符串
in.close();
}
# include<fstream>
# include<string>
int main()
{
ifstream in("input.txt");
istreambuf_iterator<char> beg(in), end;//利用以字符爲元素的流迭代器將文件流中所有的字符
string text(beg, end);//存入到字符串中
in.close();
}