Simple VECTOR usage, New to vectors

Nov 15, 2015 at 11:08pm
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
	
	
}
Nov 16, 2015 at 12:29am
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 Nov 16, 2015 at 12:31am
Nov 16, 2015 at 12:30am
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.
Nov 16, 2015 at 5:15pm
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
Nov 16, 2015 at 5:34pm
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 Nov 16, 2015 at 5:42pm
Nov 16, 2015 at 7:35pm
editting
Last edited on Nov 17, 2015 at 1:24am
Nov 16, 2015 at 8:01pm
I don't see a function

bool VectorContainsHello(vector<string>& vec)

anywhere in your code.
Nov 18, 2015 at 2:24am
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.