我在txt文档中保存一组数据
p1:
108.98399999999999
311.94000000000000
-39.25700000000000
-179.99000000000001
0.03000000000000
90.00000000000000p2:
109.60100000000000
311.86700000000002
0.74200000000000
-179.99000000000001
0.03000000000000
90.000000000000000
在vc中写一个程序把这两个数组相加,并把结果读取出来?
建一个基于对话框的程序用MFC或c++实现!
有哪位高手帮我写写代码????
p1:
108.98399999999999
311.94000000000000
-39.25700000000000
-179.99000000000001
0.03000000000000
90.00000000000000p2:
109.60100000000000
311.86700000000002
0.74200000000000
-179.99000000000001
0.03000000000000
90.000000000000000
在vc中写一个程序把这两个数组相加,并把结果读取出来?
建一个基于对话框的程序用MFC或c++实现!
有哪位高手帮我写写代码????
#include <iostream>
using namespace std;
int main()
{
ifstream p1("p1.txt");
ifstream p2("p2.txt");
double a,b;
while (p1>>a&&p2>>b)
{
cout<<a+b<<endl;
}
return 0;
}
这是C++版的,没几句话,不过要保证 p1.txt p2.txt这2个文件存在,而且里面据说个数一样才可以!
不过我的p1,p2都存在一个txt文档里面啊!而且我想用对话框实现!!
CStdioFile file;
char ccc[3000];
DWORD o=0;
int i;
file.Open("参考数据.txt",CFile::modeRead);
for(i=1;i<3000;i++)
{
ccc[i]=0;
}
file.Seek(3,CFile::begin);
o=file.GetPosition();
file.Read(&o,112); file.Seek(4,CFile::current);
o=file.GetPosition();
file.Read(&o,11); MessageBox(ccc);
CStdioFile file;
CString str;
double data = 0;
double sum = 0;
if(!file.Open("参考数据.txt",CFile::modeRead))
{
//打开文件失败
} while(file.ReadString(str))
{
if(str.Compare("P1:") == 0 || str.Compare("P2:") == 0) //p1和P2行
{
continue;
}
data = strtod(str, NULL);
sum += data;
}
str.Format("%f", sum);
MessageBox(sum);
CStdioFile file;
CString str;
double data1[2][6] = 0;
double sum[6] = 0;if(!file.Open("参考数据.txt",CFile::modeRead))
{
//打开文件失败
} int i = 0;
int block = 0;
while(file.ReadString(str))
{
if(str.Compare("P1:") == 0) //本行数据为p1:
{
block = 0;
continue;
}
if(str.Compare("P2:") == 0) //本行数据为p2:
{
block = 1;
i = 0;
continue;
}
//如果读到有空行等,在这里加入代码直接continue;
data1[block][i] = strtod(str, NULL);
i++;
}
for(i = 0; i < 6; i++)
{
sum[i] = data[0][i] + data[1][i];
}