Simple File Input/Output

For this assignment, I'm snagged on what to do next. I'm supposed to be moving contents of one file (containing about 100 random numbers and spaces) to an outfile--completely intact--except for removing any extra spaces. I can do the latter, just can't get the entire contents of the file to move to the outfile for editing. This is just the necessary parts of the program.

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
#include <iostream>
#include <fstream>
#include <cstdlib>
using namespace std;

int main()
   {
      ifstream in_stream;
      ofstream out_stream;
      
        in_stream.open("infile.cpp");
            if (in_stream.fail())
            {
                 cout << "Input file opening failed." << endl;
                 exit (1);
            }

         out_stream.open("outfile.cpp");
            if (out_stream.fail())
            {
                 cout << "Output file opening failed." << endl;
                 exit(1);
            }

/**Right here is the problem. I tried char array_infile [100].**/  
int ?? /*declarations?, initializations?*/
in_stream >> /*from infile?*/

/*This appears in the outfile above the edited version of infile*/
out_stream << "This is the edited version of infile.cpp.  All spaces of more than" << endl;
out_stream << "two have been removed.  You should see a series of numbers with only" << endl;
out_stream << "one space between each number here: "

in_stream.close();
out_stream.close();

return 0;
}

Last edited on
I think I finally found a section in the book to help me. It appears I have this set up wrong overall. (?) I'll give that a go and see what the changes reveal

K
Topic archived. No new replies allowed.