我一直在努力学习如何在低延迟交易系统的环境中优化C++,我想知道这个实现是否可以改进。无论是具体的还是一般的见解,我都很感激。
// 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; }