Skip to content

Latest commit

 

History

History
65 lines (53 loc) · 2.08 KB

io_streams.md

File metadata and controls

65 lines (53 loc) · 2.08 KB
marp theme footer
true
custom-theme

I/O streams

Streams are part of STL

STL stands for Standard Template Library We're gonna talk about it a lot!

📺 Watch the related YouTube video!


Prerequisites:


Disclaimer

  • This lecture is beginner friendly
  • There are some best practices that would use different types, but those require more in-depth understanding and will be covered later
  • What you see on this slide is the best practice until this point in the course 😉

Special symbols used in slides

  • 🎨 - Style recommendation
  • 🎓 - Software design recommendation
  • 😱 - Not a good practice! Avoid in real life!
  • ✅ - Good practice!
  • ❌ - Whatever is marked with this is wrong
  • 🚨 - Alert! Important information!
  • 💡 - Hint or a useful exercise
  • 🔼1️⃣7️⃣ - Holds for this version of C++(here, 17) and above
  • 🔽1️⃣1️⃣ - Holds for versions until this one C++(here, 11)

Style (🎨) and software design (🎓) recommendations mostly come from Google Style Sheet and the CppCoreGuidelines


I/O streams for input and output

  • Handle stdin, stdout and stderr:
    • std::cin --- maps to stdin
    • std::cout --- maps to stdout
    • std::cerr --- maps to stderr
  • #include <iostream> to use I/O streams
  • Easier to use than std::printf but slower
  • 💡 We will cover a better way for logging in the future but streams are totally good enough for now 👌
#include <iostream>
int main() {
  int some_number{};
  std::cin >> some_number;
  std::cout << "number = " << some_number << std::endl;
  std::cerr << "boring error message" << std::endl;
  return 0;
}

bg