Answer to Question #21684 in C++ for islamsaad

Question #21684
write aprogram c++ that read 10 integer value from file and print the sum into another file
1
Expert's answer
2013-01-25T03:51:25-0500

#include <fstream>
#include <iostream>
#include <string>
#include <conio.h>

void read_data();
double sum=0;
using namespace std;
int main()
{
read_data();

getch();
return 0;
}

void read_data(){
string line;
ifstream myfile ("numbers.txt");
int countofline=0;
if (myfile.is_open())
{
while ( myfile.good() )
{
getline (myfile,line);//read each lines
sum+=atof(line.c_str());
}
myfile.close();//cloe file
}
else cout << "Unable to open file

";
cout<<"Sum = "<<sum;
ofstream writefile("sum.txt");
writefile<<sum;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS