Get an istream from a char*
2015-12-07 17:05
393 查看
#include <iostream> #include <istream> #include <streambuf> #include <string> struct membuf : std::streambuf { membuf(char* begin, char* end) { this->setg(begin, begin, end); } }; int main() { char buffer[] = "I'm a buffer with embedded nulls\0and line\n feeds"; membuf sbuf(buffer, buffer + sizeof(buffer)); std::istream in(&sbuf); std::string line; while (std::getline(in, line)) { std::cout << "line: " << line << "\n"; } return 0; }
Which outputs:
line: I'm a buffer with embedded nullsand line line: feeds
相关文章推荐
- 第十五周实践项目1—验证算法(3)希尔排序
- 第4周项目3单链表应用2
- DIV CSS网站布局八个小技巧
- Android开发之TabHost应用详解
- JSON 之JAVA 解析
- Json数据的解析_Gson
- PHPnow开启PHP扩展里openssl支持的方法
- python入门篇之介绍和流程控制(一)
- 第十三周项目5—拓扑排序算法的验证
- Connecting with Wi-Fi Direct
- 第十五周项目3-B-树的基本操作
- 第15周 项目1 - 验证算法
- Remove Duplicates from Sorted List II
- datagrid 选中行事件 SelectionChanged="dataGrid2_SelectionChanged"
- 利用python对58同城西安本地服务分类提取
- [LeetCode]015-3Sum
- 第十四周项目三 二叉树排序
- 第十五周知原理题目解析
- mac office 2016 破解工具 mac版
- 单例模式