| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 498 人关注过本帖
标题:MFC对txt文件操作问题
取消只看楼主 加入收藏
suchengjie
Rank: 1
等 级:新手上路
帖 子:118
专家分:1
注 册:2013-3-2
结帖率:90%
收藏
 问题点数:0 回复次数:0 
MFC对txt文件操作问题
部分原始数据是这样的:
-9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 690 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999
最后要变成的格式为:
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
.......
......
也就是一行有十个
编写的代码如下:
得不出答案,求指教
void CProcedureViewView::OnInputData()
{
    // TODO: Add your command handler code here
    CProcedureDoc*pDoc=GetDocument();
    FILE*file;
    file=fopen("data).txt","r");
    for(int i=0;i<241;i++)   //地形数据的行数
    {
        for(int j=0;j<135;j++)   //地形数据的列数
        {
            fscanf(file,"%f",&nodexyz[i][j]);    //nodexyz[i][j]为存储地形数据的变量
        }
    }
    fclose(file);
}

void CProcedureViewView::OnOnOutputData()
{
    // TODO: Add your command handler code here
    CProcedureDoc*pDoc=GetDocument();
    int i,j,k;
    k=0;
    int len;
    CString str;
    FILE*pfile=fopen("dataout.txt","w");
    for(i=0;i<241;i++)
        for(j=0;j<135;j++)
        {
            if(nodexyz[i][j]==-9999)
            {
                xinodexyz[k]=0;   //将没有实际高程值处的高程值由原来的一9999改为0
            }
            else
                xinodexyz[k]=nodexyz[i][j];
            k++;
        }
        for(i=0;i<691380;i++)
        {
            str.Format("%12.2f\t",xinodexyz[i]);
            if(i%10==0)
            {
                str+="\n";
            }
            len=strlen(str);
            fwrite(str,1,len,pfile);
        }
        fflush(pfile);
}
2013-06-28 21:32
快速回复:MFC对txt文件操作问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.027117 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved