#include <fstream>
#include <iostream>
using namespace std;
int main()
{
// 初始化
ofstream write_txt; // 初始化输出流
// 打开文件
write_txt.open("D:\\words.txt", ios::app);
// 判断文件是否打开
if (!write_txt.is_open())
{
cout << "file open is error!" << endl;
return 0;
}
// 将文件指针置于文件末尾
write_txt.seekp(0, ios::end);
// 通过文件指针 -> 获取文件大小(字节数)
int file_size = (int)write_txt.tellp();
// 关闭文件流
write_txt.close();
// 输出文件内容
cout << "文件的字节数 = " << file_size << endl;
return 0;
}
12-08
660
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
12-23
1万+
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
04-26
2313
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交