朱色虫居
Pages
Home
Featured Posts
2007/03/11
iostream iterator
#include
#include
#include
#include
#include
using namespace std;
int main()
{
cout << "input Integers:"; istream_iterator
input(cin), end_of_stream;
ofstream even("even.txt");
ofstream odd("odd.txt");
ostream_iterator
evenIt(even, " ");
ostream_iterator
oddIt(odd, "\n");
vector
ivec;
vector
evenVec;
vector
oddVec;
copy(input, end_of_stream ,inserter(ivec,ivec.begin()));
for(vector
::iterator it=ivec.begin(); it != ivec.end(); ++it)
{
if(*it % 2){
oddVec.push_back(*it);
}
else{
evenVec.push_back(*it);
}
}
copy(oddVec.begin(), oddVec.end(), oddIt);
copy(evenVec.begin(), evenVec.end(), evenIt);
}
No comments:
Post a Comment
Newer Post
Older Post
Home
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment