63 126
Assignments Done
99,1%
Successfully Done
In July 2018

Answer to Question #55620 in C++ for harry

Question #55620
Write a program that reads a list of
names from a file called "names.txt" until it reaches end
of file, sorts them, and writes them to a second file. Be
sure not to exceed the array bounds.
Expert's answer
#include <string>
#include <iostream>
#include <fstream>
#include <list>
#include <algorithm>
#include <iterator>
using namespace std;
int main()
{
list<string> lines;
int n=0;
string a;
ifstream F;
F.open("D:\\data.txt", ios::in);
if (F){
while (!F.eof()){
F>>a;
lines.push_back(a);
}
F.close();
}
else cout<<"Error"<<endl;
lines.sort();
ofstream out("output.txt");
copy(lines.begin(), lines.end(), ostream_iterator<string>(out, "\n"));
out.close();
return 0;
}

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 first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions