在 C++ 中将整个文件读入 std::string 的最佳方法是什么?
这是在C++中将整个文件读入std::string的简单方法
算法
Begin Take the filename as inputstream. Declare a string variable str. Read the file till the end by using rdbuf(). Put the data into st. Print the data. End.
示例代码
#include#include #include #include using namespace std; int main() { ifstream f("a.txt"); string str; if(f) { ostringstream ss; ss << f.rdbuf(); str = ss.str(); } cout< 输入
a.txt data file contains the string “hi”输出结果hi
热门推荐
6 保研的祝福语简短
10 年轻20岁祝福语简短
11 朋友结婚祝福语信息简短
12 女孩婚礼贺卡祝福语简短
13 30段点歌简短祝福语
14 虎年春节祝福语图文简短
15 写给后妈祝福语大全简短
16 简短回复生日祝福语
17 校长送毕业祝福语简短
18 毕业立体贺卡祝福语简短