It is correct that a function can return at maximum one value. Since you need two return values, you'll have to pack those into some other data type.
There are several options. You can use std::tuple
, you can make a struct/class that holds two strings, you can return a vector of strings, etc.
The example below uses a vector to hold the strings.
#include <iostream>
#include <vector>
std::vector<std::string> upperLowerCase(std::string words){
std::vector<std::string> res;
res.push_back(words);
res.push_back(words);
for(int i = 0; i < words.size(); i++) {
res[0].at(i) = toupper(words.at(i));
res[1].at(i) = tolower(words.at(i));
}
return res;
}
int main() {
std::vector<std::string> v = upperLowerCase("HeLLo");
std::cout << "Upper: " << v[0] << std::endl;
std::cout << "Lower: " << v[1] << std::endl;
return 0;
}
And the example below uses std::tuple
#include <iostream>
#include <tuple>
std::tuple<std::string, std::string> upperLowerCase(std::string words){
std::string upper = words;
std::string lower = words;
for(int i = 0; i < words.size(); i++) {
upper.at(i) = toupper(words.at(i));
lower.at(i) = tolower(words.at(i));
}
return std::make_tuple(upper, lower);
}
int main() {
std::tuple<std::string, std::string> t = upperLowerCase("HeLLo");
std::cout << "Upper: " << std::get<0>(t) << std::endl;
std::cout << "Lower: " << std::get<1>(t) << std::endl;
return 0;
}