Question

create a program that sum value from a txt file in c++,the data in the txt...

create a program that sum value from a txt file in c++,the data in the txt file are in columns
0 0
Add a comment Improve this question Transcribed image text
Answer #1
#include <string>
#include <iostream>
#include <fstream>

using namespace std;

int main() {
    string filename;
    cout << "Enter file name: ";
    cin >> filename;
    ifstream in(filename.c_str());
    if (in.is_open()) {
        int num, total = 0;
        while (in >> num) {
            count++;
            total += num;
        }
        cout << "The sum of all the numbers in the file: " << total << endl;
    } else {
        cout << "can not open " << filename << endl;
    }
    return 0;
}
Add a comment
Know the answer?
Add Answer to:
create a program that sum value from a txt file in c++,the data in the txt...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT