I'm trying to pass istringstream and ostringstream by reference to a void function which would extract some substrings from the string passed in istringstream and put them into the ostringstream. The istringstream seems to be working OK, but I am baffled as to how to access the result which should be in ostringstream. Below is my code. When I trace it, I can see that the string in str does get into the function OK, but I'm baffled as to why the results don't appear in strOut. I admit I am a complete noob in working with this stringstream stuff.
void only_uppercase(std::istringstream & iss, std::ostringstream & oss);
int main()
{
string str("Hello FROM the DARK side");
string strOut = "XXXX"; // A string to store the word on each iteration.
istringstream istr_strm(str);
ostringstream ostr_strm(strOut);
only_uppercase(istr_strm, ostr_strm);
cout << strOut << endl; //Expected: FROM SIDE
}
void only_uppercase(std::istringstream & iss, std::ostringstream & oss)
{
std::string word;
while (iss >> word) {
bool should_add = true;
for (char c : word) {
if (!std::isupper(c)) {
should_add = false;
break;
}
}
if (should_add) {
oss << word << "\n";
}
}
}