Created
August 29, 2020 21:04
-
-
Save inxanedev/c1bea6718975ca7bf5b14d9ce59a4908 to your computer and use it in GitHub Desktop.
This file contains 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> | |
#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