fork download
  1. #include <iostream>
  2. #include <sstream>
  3.  
  4. enum class dna_strand : char {
  5. positive = '+',
  6. negative = '-'
  7. };
  8.  
  9. std::ostream& operator <<(std::ostream& out, dna_strand strand) {
  10. return out << static_cast<char>(strand);
  11. }
  12.  
  13. std::istream& operator >>(std::istream& in, dna_strand& strand) {
  14. char ch{};
  15. if (not in >> ch)
  16. return in;
  17. if (ch == '+')
  18. strand = dna_strand::positive;
  19. else if (ch == '-')
  20. strand = dna_strand::negative;
  21. else
  22. in.setstate(std::ios::failbit);
  23. return in;
  24. }
  25.  
  26. int main() {
  27. std::stringstream sstr("+");
  28. dna_strand s{};
  29. sstr >> s;
  30. std::cout << "\"" << s << "\"\n";
  31. }
Success #stdin #stdout 0s 3064KB
stdin
Standard input is empty
stdout
""