C++读取文件内容
来源:互联网 发布:php服务器配置 centos 编辑:程序博客网 时间:2024/05/21 14:44
#include <iostream>
#include <iomanip>
#include <fstream>
using namespace std;
int main(int argc, char **argv)
{
char buffer[256];
if(argc!=2)
{
cout << "Usage: readfile <filename> " <<endl;
exit(1);
}
//生成ifstream的对象并打开文件
ifstream input(argv[1], ios::in); // | ios::binary);
//读取失败
if(input.fail())
{
cout << "can not open the file"<<endl;
exit(1);
}
//依次读取sizeof(buffer)长度的数据,并输出
do{
//如果读取成功,则输出内容
if(input.good())
{
//input.read(buffer, sizeof(buffer));
input.getline(buffer, sizeof(buffer));
/*
for(int i=0; i<sizeof(buffer); i++)
{
if(isprint(buffer[i]))
//cout << setw(3) << hex << (int)buffer[i] << " " << setw(3) << buffer[i] << " ";
cout << setw(3) << buffer[i] << " ";
//else
// cout << setw(8) << ".";
if(i>0 && i%10==0)
cout <<endl;
}
*/
cout << buffer <<endl;
}
}while(!input.eof());
//关闭输入流
input.close();
return 0;
}
- C读取文件内容
- 二进制读取文件内容[C#]
- C格式读取文件内容
- C语言读取文件内容
- c语言 读取文件内容 文件写入
- C语言读取文件内容统计代码
- C语言读取文件内容,按行读
- C格式化读取txt文件内容
- C语言读取文件的内容
- c语言 按格式读取文件内容
- c语言:读取文件中的指定内容
- Objective-C 创建文件 读取文件内容 (NSFileManager)
- C语言逐行读取文件内容,写入另外一个文件
- c#读取Excel内容
- 使用ifstream和getline读取文件内容[c++]
- 使用ifstream和getline读取文件内容[c++]
- 使用ifstream和getline读取文件内容[c++]
- 使用ifstream和getline读取文件内容[c++]
- QQ空间欢迎动画代码大全
- asp.net 中的 WebConfig配置文件详解
- 在.net2.0以上版本中发送电子邮件的方法示例
- C++元编程和Boost编程库 (C++ Metaprogramming and Boost MPL )中部
- c#
- C++读取文件内容
- 禁止程序运行的几种方法(整理)
- Hacker学的再好,也无法入侵你的心,服务器入侵的再多,对你只有Guest
- 一个女孩的经典程序
- Chrome浏览器5个最实用的快捷方式
- Packet Tracer V5.1 完整版下载
- TORQUE
- 关于 js 实现复选框 全选
- 网站工作人员的分类