在积分程序中我们需要在E盘中建立一个记事本,以便记录数据。好了,废话不说,源码奉上:
#include<bits/stdc++.h>
#include<windows.h>
using namespace std;
int a/*[1000]*/;
//int b[1000];
int main()
{
for(;;){
cout<<"关闭程序请按Ctrl+C快捷键。"<<endl<<"请在数字前添加“+”或“-”。"<<endl;
ifstream myfile("E:\\实验者的积分程序\\实验者.txt");
int i=0;
while(!myfile.eof()) //一直读取直到文件结尾
{
myfile>>a/*[i]*/;
i++;
}
myfile.close();
//cout<<a[0];
int g,p;
char f;
map<string,int> b;
b["实验者"]=a;
cout<<"实验者有"<<b["实验者"]<<"积分。"<<endl;
cin>>f>>g;
if(f=='+') b["实验者"]+=g;
else if(f=='-') b["实验者"]-=g;
cout<<"实验者有"<<b["实验者"]<<"积分。"<<endl;
string in;
//getline(cin,a);
std::ofstream outFile;
outFile.open("E:\\实验者的积分程序\\实验者.txt");
outFile<<b["实验者"]<<endl;
outFile.close();
system("pause");
system("cls");
}
return 0;
}