如何将下面格式文件读出 坐标X 坐标Y 2 212.0 20.012.0 20.020.0 12.020.0 12.0其中 2 2度为整数值12.0读为double型 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 fstream finput;double m;finput.open(你的文件,‘r’);while(input>>m) cout<<m<<endl;貌似这样,我也弄过一个这样的 CFileDialog myopen(TRUE,NULL,apppath,OFN_NOCHANGEDIR|OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT,"table file|*.tbl||",NULL); if (myopen.DoModal()==IDOK) { fstream finput; UpdateData(); m_choosfile=myopen.GetFileName(); UpdateData(FALSE); finput.open(myopen.GetPathName()); double m; int i=0; int j=0; //========================= //read rows,col from txt || //========================= finput>>row; finput>>col; //========================================= //Create the array dymaticly || //========================================= checktable=new double*[row]; for (int tk=0;tk<row;tk++) { checktable[tk]=new double[col]; } //================================================ //write the data to array from txt file; || //================================================ while (finput>>m) { if (j>(col-1)) { j=0; i++; if (i>(row-1)) { finput.close(); return; } checktable[i][j]=m; } else { checktable[i][j]=m; }我的txt格式如下:990 0.1 0.2 0.3 0.5 0.75 1.0 2.0 10.00.01 0.428 0.368 0.349 0.331 0.320 0.318 0.315 0.3100.02 0.600 0.502 0.470 0.440 0.428 0.420 0.411 0.4040.03 0.729 0.599 0.558 0.520 0.501 0.492 0.483 0.4730.05 0.931 0.756 0.694 0.644 0.618 0.606 0.589 0.5800.07 1.075 0.873 0.801 0.742 0.711 0.697 0.672 0.6500.10 1.252 1.027 0.935 0.857 0.817 0.801 0.790 0.7390.15 1.518 1.235 1.109 1.021 0.965 0.938 0.895 0.8720.20 1.745 1.395 1.254 1.140 1.080 1.045 1.000 0.969 散分!什么时候中国会有大牛的公司? 如何隐藏一个即将被创建的窗体(外部应用程序) 请教!怎样确认光盘里是否有某个文件,我写的代码怎么也过不去,不知道哪里有问题了? 关于CSplitterWnd创建的视图的大小问题 请教VirtualAlloc和new的区别何在?有什么优点? 修改指定表的指定行指定列的值用什么函数? MFC Socket问题 MFC中报错 标示符string错误 怎样判定有几块硬盘!!!求助高手!!!!!!! 怎样在windows驱动程序中读写操作txt文件 如何让CEdit控件显示数据时自动换行啊? 如何获取树形控件里选中项目的完整路径?
double m;
finput.open(你的文件,‘r’);
while(input>>m)
cout<<m<<endl;
貌似这样,我也弄过一个这样的 CFileDialog myopen(TRUE,NULL,apppath,OFN_NOCHANGEDIR|OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT,"table file|*.tbl||",NULL);
if (myopen.DoModal()==IDOK)
{
fstream finput;
UpdateData();
m_choosfile=myopen.GetFileName();
UpdateData(FALSE);
finput.open(myopen.GetPathName());
double m;
int i=0;
int j=0; //=========================
//read rows,col from txt ||
//=========================
finput>>row;
finput>>col; //=========================================
//Create the array dymaticly ||
//========================================= checktable=new double*[row];
for (int tk=0;tk<row;tk++)
{
checktable[tk]=new double[col];
} //================================================
//write the data to array from txt file; ||
//================================================ while (finput>>m)
{
if (j>(col-1))
{
j=0;
i++;
if (i>(row-1))
{
finput.close();
return;
}
checktable[i][j]=m;
} else
{
checktable[i][j]=m;
}
我的txt格式如下:
9
9
0 0.1 0.2 0.3 0.5 0.75 1.0 2.0 10.0
0.01 0.428 0.368 0.349 0.331 0.320 0.318 0.315 0.310
0.02 0.600 0.502 0.470 0.440 0.428 0.420 0.411 0.404
0.03 0.729 0.599 0.558 0.520 0.501 0.492 0.483 0.473
0.05 0.931 0.756 0.694 0.644 0.618 0.606 0.589 0.580
0.07 1.075 0.873 0.801 0.742 0.711 0.697 0.672 0.650
0.10 1.252 1.027 0.935 0.857 0.817 0.801 0.790 0.739
0.15 1.518 1.235 1.109 1.021 0.965 0.938 0.895 0.872
0.20 1.745 1.395 1.254 1.140 1.080 1.045 1.000 0.969