Pagini recente » Cod sursa (job #1416075) | Cod sursa (job #561882) | Cod sursa (job #8292) | Cod sursa (job #761793) | Cod sursa (job #3162638)
// 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();
}