【发布时间】:2011-07-01 20:23:56
【问题描述】:
这段代码:
#include <iostream>
#include <cstdio>
#include <fstream>
#include <string>
int main()
{
std::remove("test.txt");
std::fstream f("test.txt",std::ios::in | std::ios::out | std::ios::binary | std::ios::trunc);
std::cout << f.good() << std::endl;
f<<"test"<< std::flush;
std::cout << f.tellg() << " " << f.tellp() << std::endl;
f.seekg(0);
std::string s;
f>>s;
std::cout << f.tellg() << " " << f.tellp() << std::endl;
}
在 gcc-4.4.5 中给出以下输出
1
4 4
4 4
即tellg 和 tellp 都返回了预期的流位置 4。
虽然 gcc-4.6.0
给予:
1
4 4
-1 4
我在哪里可以找到参考资料:
- 第一种情况是正确的(gcc-4.6 中的错误)
- 第二种情况是正确的(gcc
- 两种情况都正确,行为未定义
【问题讨论】:
-
std::remove怎么了?