C++ostream_iterator<string>问题
#include<iostream>#include<fstream>#include<vector>#include<algorithm>#include<string...
#include <iostream> #include <fstream> #include <vector> #include <algorithm> #include <string> #include <iterator> using namespace std ; int main() { vector<string> DocuData ; char InputDocName[50]; char OutputDocName[50] ; cin >>InputDocName >> OutputDocName ; ifstream from(InputDocName) ; if(!from) { cout <<"ERROR\n" ; return -1 ; } string line ; while(getline(from,line)) { DocuData.push_back(line) ; } sort(DocuData.begin(),DocuData.end()) ; unique_copy(DocuData.begin(),DocuData.end(), ostream_iterator<string>(cout,"\n")) ; ofstream out(OutputDocName) ; if(!out) { cout <<"ERROR\n" ; return -1 ; } unique_copy(DocuData.begin(),DocuData.end(), ostream_iterator<string>(out,"\n")) ; from.close() ; out.close() ; return 0 ; } 分析一下ostream_iterator<string>的作用,和不同之处,谢谢
展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询