1. #include<bits/stdc++.h>
    2. using namespace std;
    3. /**
    4. * 文件输入输出
    5. * */
    6. int main() {
    7. ofstream out("C:/Users/Administrator/Documents/temp.txt");
    8. ifstream in;
    9. int x, a[10];
    10. for(int i = 0; i < 10; i++) {
    11. cin>>x;
    12. out<<x<<" ";
    13. }
    14. out.close();
    15. in.open("C:/Users/Administrator/Documents/temp.txt");
    16. int j = 0;
    17. while(!in.eof()) {
    18. in>>a[j++];
    19. }
    20. in.close();
    21. int s = 0;
    22. for(int i = 0; i < 10; i++) {
    23. s += a[i];
    24. cout<<a[i]<< " ";
    25. }
    26. cout<<endl;
    27. cout<<"the sum is :"<<s<<endl;
    28. return 0;
    29. }