Web-based Compiler - Version 2.0
Created by Don Retzlaff and Tom Irby
Instructions
1. Edit the program below.
2. Enter the data values that the program reads from
cin
.
3. Enter the data values that the program reads from
in.dat
.
4. Select other Input File Stream files (if any) near bottom of the form.
5. Enter the name of any Output File Stream files the program writes.
6. Click the "Compile/Run" button.
Enter your source code here:
// main.cpp #include
#include
using namespace std; int main () { ifstream inFile; ofstream outFile; int n; // open files inFile.open("in.dat"); outFile.open("out.dat"); cout << "Enter integer value: "; cin >> n; cout << "n = " << n << endl; outFile << "Data from cin:" << endl; outFile << "n = " << n << endl; outFile << "Data from file:" << endl; if (inFile.is_open()) { inFile >> n; outFile << "n = " << n << endl; } else { outFile << "Input File not open." << endl; } return 0; }
Enter
cin
data here:
42
Enter
in.dat
data here:
43
ifstream
Files:
ofstream
File Names: