Redirecting standard in and standard out to/from files is bad practice because it contravenes the standard expectation that ``++cin++`` and ``++cout++`` do not relate to files. Additionally, it is less efficient than using file streams such as ``++ifstream++`` and ``++ofstream++``. For both of these reasons, this practice should be avoided.


== Noncompliant Code Example

----
  ifstream in("in.txt");
  cin.rdbuf(in.rdbuf()); // Noncompliant; redirects cin to in.txt

  ofstream out("out.txt");
  cout.rdbuf(out.rdbuf()); //Noncompliant; redirects cout to out.txt

  std::string line;
  while(getline(cin, line))
  {
      cout << line << endl;
  }
----


== Compliant Solution

----
  ifstream in("in.txt");

  ofstream out("out.txt");
  std::string line;
  while (inf && in >> line)
  {
    out << line << endl;
  }
----

