dimanche 16 novembre 2014

Accessing char in a vector of strings by it's iterator


Vote count:

0




Here's a part of my code:



std::vector<std::string> syntax_words;
//...
//Currently the above vector contains few strings
std::vector<std::string>::iterator sy_iterator = syntax_words.begin();

while (sy_iterator != syntax_words.end(){
if (*sy_iterator[4] == 'X'){
//...


Basically I want to access the fifth char in the current string. Unfortunately the above code is throwing an error during compilation:



error: no match for ‘operator*’ (operand type is ‘std::basic_string<char>’)
if (*sy_iterator[4] == 'X'){


I've also tried this:



if (sy_iterator[4] == 'X'){


But it's also throwing an error:



error: no match for ‘operator==’ (operand types are ‘std::basic_string<char>’ and ‘char’)
if (sy_iterator[sit] == 'X'){


What should I do to make it work?



asked 19 secs ago







Accessing char in a vector of strings by it's iterator

Aucun commentaire:

Enregistrer un commentaire