- 1、本文档共2页,可阅读全部内容。
- 2、有哪些信誉好的足球投注网站(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
- 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
VC++读取文本文件里的数据到两个数组中
VC++读取文本文件里的数据到两个数组中
1,0.056183,0.015906,0.003513,0.000283,0.000003,0.000828,0.111811
1,0.020147,0.005431,0.001509,0.000059,0.000003,0.000797,0.111808
1,0.034398,0.009768,0.001874,0.000130,0.000003,0.000805,0.111808
1,0.069287,0.019784,0.005178,0.000442,0.000003,0.000851,0.111788
2,0.026044,0.001199,0.001091,0.000081,0.000003,0.000794,0.111806
2,0.090909,0.008505,0.003210,0.001535,0.000004,0.000909,0.111562
2,0.115152,0.002632,0.006299,0.001627,0.000004,0.000825,0.111374
2,0.073055,0.001612,0.001854,0.000210,0.000003,0.000798,0.111816
3,0.354464,0.198575,0.028486,0.024844,0.000663,0.012116,0.113298
3,0.552498,0.364998,0.240247,0.210239,0.047230,0.130700,0.010317
3,0.264865,0.137833,0.013999,0.008875,0.000101,0.004152,0.111612
3,0.448321,0.263610,0.042394,0.038381,0.001551,0.020586,0.111953
3,0.218182,0.099159,0.001695,0.000309,0.000003,0.000875,0.111797
3,0.280098,0.134837,0.002879,0.004435,0.000018,0.002441,0.112025
3,0.451433,0.261783,0.084898,0.045366,0.002778,0.019255,0.069580
4,0.212613,0.098557,0.012569,0.007624,0.000077,0.003238,0.111885
4,0.264865,0.113646,0.005411,0.002057,0.000009,0.001334,0.111674
4,0.267486,0.132535,0.015797,0.009446,0.000117,0.004269,0.110818
4,0.233743,0.105773,0.023915,0.013395,0.000242,0.005248,0.111885
4,0.273055,0.132115,0.003436,0.002413,0.000009,0.001539,0.111798
上面是数据文件的一部分,其中第一列是类别标识,每一行从第二个数据起是特征属性。
首先,你要用C++语言写一个函数,从文本文件中将特征数据读入一个二维数组中,将类别标识读入一个一维数组中。
其中Index[]就是你要的类别标识数组,Property[][3]就是特征属性数组
假设你的数据文件是C:\11.txt
#include stdio.h
#include iostream.h
#include string.h
#include stdlib.h
#define N 100
void main()
{
FILE *f;
int Index[N],i=0,j;
float Property[N][7];
char str[100],*pNext;
f=fopen(C:\\11.txt,r);//打开文件
if(f==NULL) {coutError, file dont open!endl; return;}//如果文件没有打开就退出报错
while(!feof(f))//检测是否读到了文件结尾
{
fgets(str,100,f);//以文本形式从文件中读出一行
Index[i]=atoi(str);//将类别标识转换为整型数,赋值
pNext=str;
for(j=0;j7;j++)
{
pNext=strchr(pNext+1,,);//有哪些信誉好的足球投注网站数据间的分隔符
Property[i][j]=atof(pNext+1);//将类别标识转换为浮点型数
文档评论(0)