3

Just start learning CS106B , Error messages telling me something wrong with these 3 lines.

" Error : expected body of lambda expression "

string key = aToken.substr([i],1);

myMap.put(aToken.substr([i],1),1);

else {myMap[aToken.substr([i],1)] +=1};

int main() { TokenScanner myTK; myTK.setInput("Sven is Pro Moo Noob <naja>"); myTK.ignoreWhitespace(); Map <string ,int> myMap; while(myTK.hasMoreTokens()){ string aToken = myTK.nextToken(); for(int i=0;i<= int(aToken.size());i++){ string key = aToken.substr([i],1); if(!myMap.containsKey(key)){ myMap.put(aToken.substr([i],1),1); } else {myMap[aToken.substr([i],1)] +=1}; } cout << aToken << endl; } cout<< myMap.toString() << endl; return 0; }; 

1 Answer 1

2

Lambda expression is expression that usually takes form:

[capture list](parameters) {function body} 

When compiler notices your [i] it expects that it's beginning of lambda expression. There is no reason to wrap numbers in square brackets in your case.

Lambda expressions allow in-line construction of functor objects with anonymous class. See: What is a lambda expression in C++11?

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.