I've been trying to learn how to optimize C++ in the context of low latency trading systems, and am wondering if this implementation could be improved. I would appreciate any insight, either specific or general.
// Code to add each word in string to vector
int main() {
std::string originalText = "Hello World!";
std::vector<std::string> words;
words.reserve(originalText.length()); // unsure if this could be more accurate
std::size_t wStart = 0;
std::size_t pos = originalText.find(" ");
while(pos != std::string::npos) {
words.emplace_back(&originalText[wStart], pos - wStart);
wStart = pos + 1;
pos = originalText.find(" ", wStart);
}
words.emplace_back(&originalText[wStart], originalText.size() - wStart);
return 0;
}