如何在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 公司乔迁食堂祝福语简短
12 婚礼结束聚餐祝福语简短
13 儿媳买车妈妈祝福语简短
14 毕业送礼老师祝福语简短
15 同事辞职正常祝福语简短
16 恭贺新婚文案祝福语简短
17 金店立秋祝福语简短英文
18 婆婆高寿祝福语大全简短