I am taking a string message chopping it up and then building a vector out of the chopped up messages. But I am wondering how do I access the vector's entries? I have tried String accessp = str.at(1);
and String & element = str[1];
for example and am getting compilation errors. Does anyone know what I am doing wrong?
#include <iostream>
#include <string>
#include <vector>
std::vector<std::string> str;
void setup(){
std::string s = "scott>=tiger>=mushroom>=fail";
std::string delimiter = ">=";
size_t start = 0, pos;
std::string token;
while ((pos = s.find(delimiter, start)) != std::string::npos) {
token = s.substr(start, pos-start);
str.push_back(token);
start = pos + delimiter.size();
}
if (start < s.size())
str.push_back(s.substr(start));
for(auto &elem : str)
std::cout << elem << std::endl;
}
void loop(){
}