If you use
operator >>
or
operator <<
it will skip whitespace, which is why doing
cin >> someStr
will only get you
if you enter
in the command line. That can present a whole host of other issues if you aren't aware of that, but I won't get into it here.
You can do what you're doing now by using
get
to retrieve a character. You can use
put
to place a single character into your output file (see
http://www.cplusplus.com/reference/ostream/ostream/put/).
You'll also want to check your value-wrapping logic and make sure you clamp your char values properly. For uppercase, you'll want to clamp it between 65 and 90. For lowercase, you'll want to clamp it between 97 and 122 (see
http://en.cppreference.com/w/cpp/language/ascii), unless you want letters to be able to turn into non-alphabetic characters (eg 'A' turns into '*' with the right value), but that would be a somewhat odd shift-cipher.
Also, you can use
isspace
to check if a characer is a whitespace character so you can ignore it (see
http://www.cplusplus.com/reference/cctype/isspace/), unless you want to handle alpha and numerics differently, in which case you're probably fine.
TLDR: use
operator <<
and
operator >>
to skip over whitespace. Use
get
and
put
to read character-by-character.
You could also read the entire file into a buffer and then iterate over that buffer, which would be arguably faster.
Also, is that function supposed to be recursive? I don't think you'll want that to be recursive.