C++读取txt文件的方法
2011-10-27 18:06
691 查看
// win32console.cpp : 定义控制台应用程序的入口点。 //C++读取txt文件的方法 #include "stdafx.h" #include <fstream> #include <iostream> using namespace std; typedef struct node{ int data; struct node *next; } node; node *creat(ifstream &ifp) { node *h=NULL,*p=NULL,*q=NULL; int data; while (ifp>>data) { p=new node; p->data=data; p->next=NULL; if (!h) h=p; else q->next=p; q=p; } return h; } void prt(node *h) { if (h) { cout<<h->data<<endl; prt(h->next); } } int _tmain(int argc, _TCHAR* argv[]) { //--file1 open ifstream fp("d:\\data.txt",ifstream::in); node *hst=creat(fp); fp.close(); prt(hst); //--file2 open ifstream r("d:\\test.txt",ifstream::in); if(!r) { cout<<"打开文件出错!"<<endl; } else { char line[4000]; //[100]2000 while(r>>line) { cout<<line<<endl; } r.close(); } //stop screen char q; cin>>q; return 0; } //--------------------------------------------------------------------------- //d:\\data.txt 内容 //1 2 3 4 5 6 //7 8 9 10 11 12 //100998877 //55 56 57 58 59 60 //d:\\test.txt 内容 //姓名:hehe年龄:12备注:123 //姓名:haihai年龄:18备注:12ff //姓名:aa年龄:22备注:ff11 //objectarx 文件处理方法 //使用纯c++来处理文本文件,可以使用ifstream、ofstream以及iofstream, //在arx中由于强制使用unicode,应该使用arx提供的AcFStream
相关文章推荐
- C++中Txt文件读取和写入(方法汇总)
- C++ 利用string读取txt文件的方法
- C++读取txt文件的方法
- c++调用其它程序的方法,以及读取本地txt文件方法。
- C++从txt文件中读取二维的数组方法
- Python实现读取txt文件并转换为excel的方法示例
- 读取TXT文件内容的方法
- Matlab中读取txt文件的几种方法
- java读取TXT文件的方法
- C++学习--向txt文件写入数据、读取数据、获取行数以及删除文件
- Java读取txt文件中的数据赋给String变量方法
- 读取TXT文件内容的方法
- Python txt文件读取写入字典的方法(json、eval)
- JAVA读取WORD,EXCEL,PDF,TXT,RTF,HTML文件文本内容的方法
- 【转】探寻C++最快的读取文件的方案(方法未论证)
- java读取TXT文件的方法
- JAVA读取WORD,EXCEL,PDF,TXT,RTF,HTML文件文本内容的方法示例
- 一个可以从txt文件中逐行(可设置)读取文本的方法
- c++学习笔记—c++对txt文件的读取与写入
- 对python .txt文件读取及数据处理方法总结