| | |
Vectors
Thread Solved |
•
•
Join Date: Nov 2009
Posts: 37
Reputation:
Solved Threads: 0
Hey everyone,
im trying to get to know vectors but i came to a point that my current knowledge stops and i need more help,
i found a program which i would like to understand but i couldn't figure it out.
here is the code:
can somebody explain to me line 1,2 and three (where it is shown as comments)
in detail because i am really struggling to understand how it works thanks a lot
im trying to get to know vectors but i came to a point that my current knowledge stops and i need more help,
i found a program which i would like to understand but i couldn't figure it out.
here is the code:
C++ Syntax (Toggle Plain Text)
#include<iostream> #include<vector> #include<string> #include<iterator> using namespace std; bool islowerCase(char c) { return islower(c); } int main() { const int size=10; vector<char>v1; vector<char>::iterator lastElem; const char charList[size]={'w','W','b','B','C','E','w','F','B','m'}; for(int i=0;i<size; i++) { v1.push_back(charList[i]); } lastElem =remove_if(v1.begin(), v1.end(), islowerCase);//line1 ostream_iterator<char> screen(cout, "");//line2 copy(v1.begin(), lastElem, screen);//line3 cout<<endl; }
can somebody explain to me line 1,2 and three (where it is shown as comments)
in detail because i am really struggling to understand how it works thanks a lot
1
#3 Dec 7th, 2009
C++ Syntax (Toggle Plain Text)
lastElem =remove_if(v1.begin(), v1.end(), islowerCase);//line1
Line 1 : remove_if(...), if the containers contains a lower case character
the function removes it. It does this, and returns the a pointer that
points to the new end since some elements has been deleted.
C++ Syntax (Toggle Plain Text)
ostream_iterator<char> screen(cout, "");//line2
ostream object, cout. When you do :
C++ Syntax (Toggle Plain Text)
cout << 'a';
C++ Syntax (Toggle Plain Text)
screen = 'a';
C++ Syntax (Toggle Plain Text)
copy(v1.begin(), lastElem, screen);//line3
Remember what I said, if you do screen = 'a'; It will print out a into the
console. So the above code roughly does screen = vec[0] ... vec[lastElement]. That means everything inside the vector is getting
printed to the screen.
Also check this out for some reference : remove_if , istream_iterator using std::copy
Go ahead and try to solve this euler problem, if u can. Check with me for hints and answers. Good Luck Solved by:tux4life, "your name here"
![]() |
Similar Threads
- Vectors Versus Arrays (Java)
- Using Vectors and Arrays with fstream (C++)
- minor problem with vectors and OOP (C++)
- Help with vectors and structs (C++)
- help with vectors (C)
- Alphabetically Order Vectors Elements (Java)
- Vectors, Functions, and Sorting... oh my! (C++)
Other Threads in the C++ Forum
- Previous Thread: overload operators
- Next Thread: sleep() error, help!
Views: 411 | Replies: 3
| Thread Tools | Search this Thread |
Tag cloud for C++
6 algorithm array arrays assignment beginner binary c++ c++borland c/c++ calculator char class classes code compile compiler constructor conversion convert count delete dll dynamic encryption error file files filestream forms fstream function functions game givemetehcodez graph graphics gui homework iamthwee input int integer lazy linker list loop loops map math matrix member memory network newbie news number object objects opengl operator output parameter pointer pointers problem program programming project qt random read reading recursion recursive reference return server sort spoonfeeding string strings struct student studio template templates text time tree variable vc++ vector video visual win32 window windows winsock wxwidgets






