Hello, I was wondering if anyone could help me with a small problem that I have. I am trying to write a code that adds the integers from a file, but I just don't know the formula to do so. The integers in the file are ordered from 1 ,2 ,3 ,4, 5... all the way to 100.
I have looked countless times in this forum for an answer to this small problem (and I'm sure there is) but there hasn't been a post that helped me understand. If anyone could help me I would truly appreciate it.
The code below outputs the content of the file to a string and now all I want to do is find the total sum of the integers(in the file) and assign the sum to a variable so i can output it.
#include <iostream>
#include <fstream>
usingnamespace std;
int main() {
int a,b,c;
fstream file;
file.open("numbers.txt");
if (file.is_open())
{
file >> a >> b >> c;
cout << a << b << c;
}
return 0;
}