I made a string of States and under it a corresponding string of Capitals. I have it so it randomly pick a state and ask for capital or pick a capital and ask for state. Sometimes it repeats and I am trying to have it make a list of the states it has selected already. then check the next time it picks if its already been picked. if it has, I want it to pick another one.
I have this:

std::string State[]{...}
std::string Capital[]{...}

const int iState = sizeof (State) / sizeof (std::string);
const int iCapital = sizeof (Capital) / sizeof (std::string);

std::vector<std::string> StatesPicked;
std::vector<std::string> CapitalsPicked;

...

int iStateSelected = rand() % iState;

//sends the last state picked to the end of the StatesPicked
StatesPicked.push_back(State[iStateSelected]);

std::vector<int>::iterator StateList;

int N = 0;

for( StateList = StatesPicked.begin() + N; StateList < StatesPicked.end(); N++)

my code is all split up. I am having a "no operator "=" matches these operands" for the = and the < in the for statement. I'm sure you can figure it out. but i have it randomly select a state. put it into the back of the vector StatesPicked. then im trying to add it to StateList. then test the new Randomly selected word with the olds. if they match then select a new one. Also need help going through the whole vector the check. if there is a different/ easier method i am open for anything that will help
Please help me! and p.s i am kinda intermediate/ beginner with C++

2
Contributors
1
2
Views
7 Years
Discussion Span
Last Post by thelamb

Your StateList is defined as vector<int>::iterator.
StatesPicked is vector<std::string>.

So StatesPicked.begin() will return a vector<std::string>::iterator, not vector<int>::iterator.

Also, why do you do StatesPicked.begin() + N ? N is 0 so what would be the effect?

If you're able to use C++0x features, you can write the code like this:

``````#include <algorithm>

std::for_each( StatesPicked.cbegin(), StatesPicked.cend(), [] (const std::string& state) {
std::cout << "State picked: " << state << "\n";
}
);``````

This weird looking [] () is called a 'Lambda'.

Edited by thelamb: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.