资源描述:
《VC读取文本文件里的数据到两个数组中.doc》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、VC++读取文本文件里的数据到两个数组中VC++读取文本文件里的数据到两个数组中1,0.056183,0.015906,0.003513,0.000283,0.000003,0.000828,0.1118111,0.020147,0.005431,0.001509,0.000059,0.000003,0.000797,0.1118081,0.034398,0.009768,0.001874,0.000130,0.000003,0.000805,0.1118081,0.069287,0.019784,0.005178,0.0004
2、42,0.000003,0.000851,0.1117882,0.026044,0.001199,0.001091,0.000081,0.000003,0.000794,0.1118062,0.090909,0.008505,0.003210,0.001535,0.000004,0.000909,0.1115622,0.115152,0.002632,0.006299,0.001627,0.000004,0.000825,0.1113742,0.073055,0.001612,0.001854,0.000210,0.000003
3、,0.000798,0.1118163,0.354464,0.198575,0.028486,0.024844,0.000663,0.012116,0.1132983,0.552498,0.364998,0.240247,0.210239,0.047230,0.130700,0.0103173,0.264865,0.137833,0.013999,0.008875,0.000101,0.004152,0.1116123,0.448321,0.263610,0.042394,0.038381,0.001551,0.020586,0
4、.1119533,0.218182,0.099159,0.001695,0.000309,0.000003,0.000875,0.1117973,0.280098,0.134837,0.002879,0.004435,0.000018,0.002441,0.1120253,0.451433,0.261783,0.084898,0.045366,0.002778,0.019255,0.0695804,0.212613,0.098557,0.012569,0.007624,0.000077,0.003238,0.1118854,0.
5、264865,0.113646,0.005411,0.002057,0.000009,0.001334,0.1116744,0.267486,0.132535,0.015797,0.009446,0.000117,0.004269,0.1108184,0.233743,0.105773,0.023915,0.013395,0.000242,0.005248,0.1118854,0.273055,0.132115,0.003436,0.002413,0.000009,0.001539,0.111798上面是数据文件的一部分,其中第
6、一列是类别标识,每一行从第二个数据起是特征属性。首先,你要用C++语言写一个函数,从文本文件中将特征数据读入一个二维数组中,将类别标识读入一个一维数组中。其中Index[]就是你要的类别标识数组,Property[][3]就是特征属性数组假设你的数据文件是C:11.txt#include"stdio.h"#include"iostream.h"#include"string.h"#include"stdlib.h"#defineN100voidmain(){FILE*f;intIndex[N],i=0,j;floatPrope
7、rty[N][7];charstr[100],*pNext;f=fopen("C:\11.txt","r");//打开文件if(f==NULL){cout<<"Error,filedon'topen!"<8、(pNext+1,',');//搜索数据间的分隔符Property[i][j]=atof(pNext+1);//将类别标识转换为浮点型数,赋值}i++;}fclose(f);//关闭文件。}嗯,突然明白LZ的意思了#includevoidmai