如何在C ++中将文件内容读入istringstream?
这是一个C++程序,用于在C++中将文件内容读取到isstringstream中。
示例
#include <fstream>
#include <sstream>
#include<iostream>
using namespace std;
int main() {
ifstream is("a.txt", ios::binary );
// get length of file:
is.seekg (0, std::ios::end);
long length = is.tellg();
is.seekg (0, std::ios::beg);
// allocate memory:
char *buffer = new char [length];
// read data as a block:
is.read (buffer,length);
// create string stream of memory contents
istringstream iss( string( buffer ) );
cout<<buffer;
// delete temporary buffer
delete [] buffer;
// close filestream
is.close();
}输出结果
hi nhooo
热门推荐
10 奶奶八十寿辰祝福语简短
11 Q穷人结婚祝福语简短
12 婶婶生日贺词简短祝福语
13 特别的端午祝福语简短
14 简短长辈新年祝福语
15 入学祝福语简短走心
16 群里祝福语简短幽默
17 周末祝福语正能量简短
18 初八祝福语简短语