Simple VECTOR usage, New to vectors

I am at the stage of storing my strings into a vector, could use some help
Please.
Also once i have my two lists of vectors is there a way to compare the two vectors together so i know which elements to pop_

1
2
3
4
5
6
  void openTagStow(string hold, vector<string>& myVector) {
	myVector.insert(myVector.begin(),hold);
	cout << myVector.begin << endl;// error is right here, not sure how it is suppose to work
	
	
}
is there a way to compare the two vectors together
Have you read the documentation for vector?
http://en.cppreference.com/w/cpp/container/vector

At the bottom of the page, you'll notice there's an operator==.
http://en.cppreference.com/w/cpp/container/vector/operator_cmp

cout << myVector.begin << endl;// error is right here, not sure how it is suppose to work
Forgot () after begin? It's a function call remember.
Last edited on
You can use vector of strings the same as vectors of any other type.

So:

myVector.push_back(hold);
cout << myVector.back() << endl;

You can't compare two vectors except by comparing them element by element.
kbw - i added () oginally but got an error stating - no operator "<<" mathes these operands

Kevin C - yes i want to compare the elements of each vector at a time : vector1 will contain "Hello" and if vector 2 contains "/Hello" then i want to pop both elements off
First, write a function:

bool VectorContainsHello(vector<string>& vec)

It should return true if vector 'vec' contains "Hello", and false otherwise. Post the code here, and then we can comment on it and give you further instructions.
Last edited on
editting
Last edited on
I don't see a function

bool VectorContainsHello(vector<string>& vec)

anywhere in your code.
yeah i was doing it a crazy weird way, a better way was to use a peek function and substr to compare open tags to closed tags storing only open tags
Topic archived. No new replies allowed.