#include <iostream>
#include <string>
#include <vector>
int lengthOfLastWord(std::string str) {
std::vector<std::string> vec;
std::string word = "";
for (char c : str) {
if (c == ' ') {
vec.push_back(word);
word = "";
} else {
word += c;
}
}
vec.push_back(word);
return vec.back().length();
}
int main() {
std::string str = "java c++ go javascript rust";
std::cout << "The length of the last word = " << lengthOfLastWord(str);
}
/*
run:
The length of the last word = 4
*/