file.open("delete_test.txt",ios::nocreate);
// 验证它是否返回该值
if(file.rdstate() == ios::failbit)
cout << "error...!\n"; // 耶,成功了
file.close();
}
putback() —— 此函数将返回最后一个所读取字符,同时将内置指针移动-1个字符。换言之,如果你使用get()来读取一个字符后再使用putback(),它将为你返回同一个字符,然而同时会将内置指针移动-1个字符,所以你再次使用get()时,它还是会为你返回同样的字符。下面是示例代码:
#include <fstream.h>
void main()
{
// test_file.txt应包含内容"hello world"
ifstream file("test_file.txt");
char ch;
file.get(ch);