Cod sursa(job #3162638)

Utilizator wappy86Cristian Florea wappy86 Data 29 octombrie 2023 16:10:40
Problema A+B Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.68 kb
// basic file operations
#include <iostream>
#include <fstream>
using namespace std;

int main()
{
    // Create a text string, which is used to output the text file
    string myText;
    int total = 0;

    // Read from the text file
    ifstream MyReadFile("adunare.in");
    ofstream MyWriteFile("adunare.out");

    // Use a while loop together with the getline() function to read the file line by line
    while (getline(MyReadFile, myText))
    {
        // Output the text from the file
        cout << myText << "\n";
        total += stoi(myText);
    }

    MyWriteFile << total;

    // Close the file
    MyReadFile.close();
    MyWriteFile.close();
}