It sounds like you could make your life easier by using something like this.
Code:
#include <iostream>
#include <vector>
#include <string>
#include <algorithm> // for std::find
class Data {
private:
std::vector<std::string> data;
public:
void add(std::string s);
bool contains(std::string s);
};
void Data::add(std::string s) {
data.push_back(s);
}
bool Data::contains(std::string s) {
std::vector<std::string>::iterator found
= std::find(data.begin(), data.end(), s);
// If s does not exist within the range [begin(), end()) then
// end() will be returned, meaning that false should be returned
// from this function. Likewise, if s does exist then some value
// other than end() will be stored in found and true is thus
// returned.
return found != data.end();
}
int main() {
Data data;
data.add("one");
data.add("two");
if(data.contains("two")) std::cout << "contains \"two\"\n";
else std::cout << "does not contain \"two\"\n";
if(data.contains("four")) std::cout << "contains \"four\"\n";
else std::cout << "does not contain \"four\"\n";
return 0;
}
The output is
Code:
contains "two"
does not contain "four"