Chinaunix首页 | 论坛 | 博客
  • 博客访问: 831636
  • 博文数量: 158
  • 博客积分: 4380
  • 博客等级: 上校
  • 技术积分: 2367
  • 用 户 组: 普通用户
  • 注册时间: 2006-09-21 10:45
文章分类

全部博文(158)

文章存档

2012年(158)

我的朋友

分类: C/C++

2012-11-23 15:55:56

#include
#include
using namespace std;

int main()
{
    fstream f("a.txt",ios::out|ios::in|ios::trunc);
    f << "abcdefg\n"; // f << "abcdefg"; 就是多了个\n,所以来问题了
    f.seekg(0);

    char ch;
    cout << "tellg=" << f.tellg() << endl;
    f >> ch;
    cout << ch << endl;
    cout << "tellg=" << f.tellg() << endl;
    f >> ch;
    cout << ch << endl;
    cout << "tellg=" << f.tellg() << endl;

    system("pause");
    return EXIT_SUCCESS;
}
输出为
tellg=0
a
tellg=2
c
tellg=4
而不是
tellg=0
a
tellg=1
b
tellg=2

------ 2007-05-14:经 提醒,此帖重复,原帖为 http://blog.vckbase.com/bruceteen/archive/2006/03/27/18761.html

阅读(2093) | 评论(13) | 转发(0) |
给主人留下些什么吧!~~

网友评论2012-11-23 15:58:13

周星星
记忆里->记忆力
---
谢谢,用拼音输入法经常会出这样的错。
有些错误还特别隐蔽,比如有时想打n个字,当打出n-1个字时,看一眼全正确的,打完最后一个字时,输入法程序会“智能”的调整前面的字,一不小心就错了。

网友评论2012-11-23 15:58:04

szz
# re heroboy:  2007-05-14 09:31  周星星
:)谢谢,我要狂晕1万次,看来我记忆里下降很多了。  

行不行啊,小周,我这么崇拜你还写错别字,让我理解了半天才做出这个判断:“记忆里->记忆力 你这个字真得写错了”

网友评论2012-11-23 15:57:57

liangxiao
我也用mingw, 另外加用了NetBeans 做为ide. 他的代码补全功能非常强. 主要我是写JAVA的.如果不是JAVA程序员就不要用NETBEANS了.

网友评论2012-11-23 15:57:37

snija
Mingw GCC 有4.2.1了,还用3.4.2?

网友评论2012-11-23 15:57:30

100000
为什么最近blog没有更新呢?
关注N久了呀~~~~~~~