I have long list of strings that I want to put define and declare in its own .h file. I want to group these strings into vectors, and use these values in a different .h file. The second file will std::find to see if a string is in the vector. Are vectors a good way group the strings to do this or should I use another method?
I have a kitBreakdown.h file will have multiple vectors of strings like the following:
#ifndef KIT_BREAKDOWN_H
#define KIT_BREAKDOWN_H
#include <vector>
void setup(){
std::vector<std::string> Bricks_Plates;
Bricks_Plates.push_back("2_1_plate"); //4211398
Bricks_Plates.push_back("2_1_brick"); //4211388
Bricks_Plates.push_back("2_2_brick"); //4211387
Bricks_Plates.push_back("4_1_plate"); //4211445
Bricks_Plates.push_back("4_2_plate"); //4211444
Bricks_Plates.push_back("6_2_plate"); //4211542
Bricks_Plates.push_back("8_2_plate"); //4211449
Bricks_Plates.push_back("2_1_smooth_plate"); //4211052
}
#endif
I want to use these strings in a different file called searchControl.h, which contains a searchControl class to implement a robotic search.
#include "kitBreakdown.h"
#include <algorithm>
// The purpose of this class is to implement a search control structure
// So individual variables can be set up (limbs and cameras) before hand
// Search Geometry should be set and checked to ensure valid choices are made
class SearchControl
{ ...
private:
void _init_search();
...
std::vector<std::string> Bricks_Plates;
};
void SearchControl::_init_search()
{...
std::cout<<"What is your Desired Piece Type?\n";
int i = 0;
while (i==0)
{
std::cin >> _desired_piece;
if (std::find(Bricks_Plates.begin(),Bricks_Plates.end(), _desired_piece) !=Bricks_Plates.end())
{
std::cout << "Cool. " << _desired_piece << " will go in one bin and anything else will go in another\n";
i=1;
}
else {
std::cout << "I don't recognize what you want\n";
std::cout << "Your Choices are...\n";
for (int j=0; j<Bricks_Plates.size(); j++) {
std::cout<< Bricks_Plates[j]<< "\n";
}
std::cout << "Enter a new Desired Piece Type:\n";
}
}
}
I want this to ask for the _desired_piece, check if _desired_piece is in Brick_Plates vector, and carry out the if statement accordingly. However when I run this code it outputs no elements of the Brick_Plates vector. How can I pass the values of the strings in the first header file to the second one?