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.
1
Expert's answer
2015-10-22T02:30:54-0400
#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 the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS