Skip to content

Instantly share code, notes, and snippets.

@inxanedev
Created August 29, 2020 21:04
Show Gist options
  • Save inxanedev/c1bea6718975ca7bf5b14d9ce59a4908 to your computer and use it in GitHub Desktop.
Save inxanedev/c1bea6718975ca7bf5b14d9ce59a4908 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <string>
#include <sstream>
class FizzBuzz {
private:
int m_Current;
std::ostringstream m_Stream;
public:
FizzBuzz() {
m_Current = 0;
}
std::string next() {
m_Current++;
m_Stream.str("");
m_Stream.clear();
if (m_Current % 3 == 0) m_Stream << "Fizz";
if (m_Current % 5 == 0) m_Stream << "Buzz";
if (static_cast<int>(m_Stream.tellp()) == 0) m_Stream << m_Current;
return m_Stream.str();
}
};
int main() {
FizzBuzz fizzbuzz;
for (int i = 0; i < 100; i++) {
std::cout << fizzbuzz.next() << std::endl;
}
std::cin.get();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment