Created
May 11, 2014 20:25
-
-
Save dgodfrey206/9372ca6d76401a1aee5c to your computer and use it in GitHub Desktop.
A stream buffer that capitalizes every word of a sentence.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
class stream_buffer : public std::streambuf | |
{ | |
public: | |
stream_buffer(std::ostream& os) | |
: whitespace(true), | |
ctype(std::use_facet<std::ctype<char>>(getloc())), | |
m_sbuf(os.rdbuf()) | |
{ } | |
int_type overflow(int_type c) | |
{ | |
int_type res | |
= m_sbuf->sputc(whitespace ? std::toupper(c) : c); | |
whitespace = ctype.is(ctype.space | ctype.punct, c); | |
return res; | |
} | |
private: | |
bool whitespace; | |
const std::ctype<char>& ctype; | |
std::streambuf* m_sbuf; | |
}; | |
int main() | |
{ | |
stream_buffer sb(std::cout); | |
std::ostream os(&sb); | |
os << "hello my name is david.how are you"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment