Skip to content

Instantly share code, notes, and snippets.

@thabetx
Created April 6, 2017 17:57
Show Gist options
  • Save thabetx/fa8b6739cfe95e7387ed3db7a64f2e43 to your computer and use it in GitHub Desktop.
Save thabetx/fa8b6739cfe95e7387ed3db7a64f2e43 to your computer and use it in GitHub Desktop.
input and output using files
#include <iostream>
#include <stdio.h>
using namespace std;
int main() {
// use in.txt as the input stream
freopen("in.txt", "r", stdin);
// use out.txt as the output stream
freopen("out.txt", "w", stdout);
// make sure that those files are in the same directory of the cpp file
// you can now cin from the input file and cout to the output file
int x;
cin>>x; // wil read an integer from the input file
cout<<x; // will write x to the output file
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment