#include
#include
#include
#include
using namespace std;
struct ft
{int psi,r;
};
int len;//文件行数 全局变量
int CountLines(const char *filename)
{
ifstream ReadFile;
int n = 0;
string tmp;
ReadFile.open(filename, ios::in);//ios::in 表示以只读的方式读取文件
if (ReadFile.fail())//文件打开失败:返回0
{
return 0;
}
else//文件存在
{
while (getline(ReadFile, tmp, ‘\n’))
{
n++;
}
ReadFile.close();
return n;
}
}
ft* CreateftFromFile(const char *fname)
{
ifstream in(fname);
if (!in){ cout << “No such a file” << endl; return NULL; }
ft s;
ft *stu = new ft[len];
int i = 0;
while (in >> s.r >> s.psi)
{
stu[i] = s;
++i;
}
in.close();
return stu;
}
void DestroyftStruct(ft *&s)
{
if (s==NULL){ cout << “无信息” << endl; return; }
delete[] s;
s = NULL;
}
void test0()
{
cout << “最后结果” << endl;
ft s1 = CreateftFromFile(“C://Users//15595//Desktop//chengji1.txt”);
ft s2 = CreateftFromFile(“C://Users//15595//Desktop//chengji2.txt”);
len=CountLines(“C://Users//15595//Desktop//chengji1.txt”);
long result=0;
for(int i=0;i<len;i++)
{result+=s1->rs1->psis2->psi;
s1++;
s2++;
}
cout<<result<<endl;
}
int main()
{
test0();
cout<<len<<endl;
return 0;
}