Question about input and output

I have an assignment problem to solve. I need to write a C++ program which takes a text file as input and produces another text file as output. The problem says that I cannot store the input file or output file in RAM. What does this exactly mean?

Pls help
You may benefit from looking at this code here, although I'm not entirely sure it meets your requirements.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include <iostream>
#include <fstream>
#include<string>
using namespace std;
int main()
{
    string r_content,w_content,test;
    fstream outfile;
    outfile.open ("data.txt",ios_base::out);
    if (!outfile)
    {
       cout<<"Error writing to file!";
       return 0;
    }
    else
    {
    cout<<"Please enter a string to be written to the file:\n";
    getline(cin,w_content);
    cout<<"Writing to file...\n";
    //send data to file before closing
    outfile<<w_content;
    outfile.close();
    }

    fstream infile;
    infile.open("data.txt",ios_base::in);
    if (!infile)
    {
        cout<<"Error reading file!";
        return 0;
    }
    else
    {
    cout<<"\nReading from file...\n";
    //read data in before closing
    getline(infile,r_content);
    cout<<"The file contents are:\n";
    cout<<r_content;
    infile.close();
    }
}

Changing the order of input/output and making one of them use a different file name may be what you need.
Last edited on
The problem says that I cannot store the input file or output file in RAM. What does this exactly mean?

It means that you'll have to read in, process, and write out to your files one portion at a time. Some I/O methods read in the whole input first and/or generate the whole output before writing, and that is not allowed for your assignment.
Topic archived. No new replies allowed.