C++标准库处理字符流时getline的一个坑
来源:互联网 发布:知到智慧树电脑客户端 编辑:程序博客网 时间:2024/06/07 11:07
一、描述
如果字符流最后没有一个空白行,那么getline处理最后一行的数据时,seekg会失效
二、代码测试
#include <sstream>#include <iostream>using namespace std;int main(int argc, char** argv){ const char* cs = "line1\nline2\nline3"; stringstream ss(cs); for (int i = 0; i < 2; ++i) { streamoff pos = ss.tellg(); string s; getline(ss, s); cout << s << endl; cout << "**" << endl; cout << pos << endl; } cout << endl << "------------------------------------------" << endl << endl; for (int i = 0; i < 2; ++i) { streamoff pos = ss.tellg(); string s; getline(ss, s); cout << s << endl; cout << "$$" << endl; cout << pos << endl; ss.seekg(pos, ios::beg); } return 0;}
0 0
- C++标准库处理字符流时getline的一个坑
- C++标准库getline函数的使用
- [C/C++标准库]_[初级]_[C++ iostream read getline 读取文件慢的原因]
- c函数-标准读入一个字符
- C标准库 memset 的一个问题
- 标准流类的成员函数getline,get,put
- getline的一个问题
- c的库函数getline
- C标准库中字符与数字的转换函数
- C++:cin、cin.getline()、getline()的用法
- C++:cin\cin.getline()\getline()的用法
- C标准库源码解剖(3):字符处理函数ctype.h和wctype.h
- C标准库学习之<ctype.h> ——字符处理
- C标准规定的转义字符
- c标准规定的转义字符
- 标准的ANSI C字符串函数和它们的等价Unicode函数 字符串处理函数对照表[宽字符处理与ANSI字符处理]
- C的字符处理函数
- C常用的字符处理
- iOS开发之block使用小结
- poj 2114 树分治(是否存在长度恰为k的路径)
- js 中indexOf()函数的用法
- Sourcecode online
- Android Studio的使用之 添加重载函数的方法
- C++标准库处理字符流时getline的一个坑
- 图片的拉伸
- Linux常用命令大全
- as3的递归原来还可以这么写
- weblogic10.3 java.lang.OutOfMemoryError: PermGen space
- http://write.blog.csdn.net/postedit/44154725
- DOM操作Manipulation
- 关于委托的知识总结
- Qt 程序窗口最大、最小化相关的设置方法