I'm having an issue where when I try to access a string that's the main param in a lambda, the compiler doesn't recognize it as so when I try to call functions using that string.
Here is my code:
void removePunctuation(std::vector<std::string> &inTokens,
std::vector<std::string> &outTokens) {
std::for_each(inTokens.begin(), inTokens.end(), [outTokens](std::string s) {
std::string newS = s;
// newS.erase(std::remove_if(newS.begin(), newS.end(), ispunct));
outTokens.push_back(newS);});
}
And the following error is produced:
a2.cpp:114:19: error: no matching member function for call to 'push_back'
outTokens.push_back(newS);});
I am also getting this sort of error in other functions, when I try to call a function that uses the lambda's string param in its call.
Any help is much appreciated!
By default, lambda arguments are passed as read-only, try
[&outTokens](std::string s)
(It is perhaps what you want anyway, if the outTokens parameter is expected to be modified.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With