fork download
  1. #include <iostream>
  2. #include <sstream>
  3. #include <vector>
  4.  
  5. std::string toCamelCase(const std::string& text) {
  6. std::stringstream ss(text);
  7. std::vector<std::string> words;
  8. std::string word;
  9.  
  10. while (ss >> word) {
  11. words.push_back(word);
  12. }
  13.  
  14. std::string camelCaseText = words[0];
  15. for (size_t i = 1; i < words.size(); ++i) {
  16. word = words[i];
  17. if (!word.empty()) {
  18. word[0] = std::toupper(word[0]);
  19. camelCaseText += word;
  20. }
  21. }
  22.  
  23. return camelCaseText;
  24. }
  25.  
  26. int main() {
  27. std::string inputText = "BOB loves-coding";
  28. std::string outputText = toCamelCase(inputText);
  29. std::cout << outputText << std::endl;
  30. return 0;
  31. }
Success #stdin #stdout 0.01s 5288KB
stdin
BOB loves-coding
stdout
BOBLoves-coding