Hello noob question here. I'm learning strings and am currently writing a program that takes a string and alternates caps with the first letter starting as lower case. The problem I'm having is that if the string has spaces, it messes up the alternating pattern. I was wondering if there was a way to skip the spaces or ignore them? heres what I have so far.
#include<string>
#include <iostream>
std::string convertToAltCaps(std::string str) {
for (int i = 0; i < str.length(); i++) {
if (str[i] >= 'A' && str[i] <= 'Z' || str[i] >= 'a' && str[i] <= 'z') {
if (i % 2 != 0) {
str[i]= toupper(str[i]);
}
else {
str[i]=tolower(str[i]);
}
}
}
return str;
}