Answer to Question #21684 in C++ for islamsaad
write aprogram c++ that read 10 integer value from file and print the sum into another file
1
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!
Learn more about our help with Assignments:
C++
Comments
Leave a comment