How do i assign things on a .txt list to a variable?

I am not understanding, and sadly getting frustrated, on how to assign the info from a 10 line (ex. of one line: 10 0 Im Frustrated) list in a .txt file to variables in a program.
I have to then read from that list and then write to a results.txt file. heres what i have:
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
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <iomanip>

using namespace std;

int main(int argc, char *argv[])
{
    fstream readFile;
    const int SIZE = 100;
    char info[SIZE];
    
    
    readFile.open("Bands.txt", ios::in);
    cout << "Here's the rank/sales/band name: \n";
    
    if (!readFile)
        cout << "ERROR: cannot open file! \n";       
    readFile.getline(info, SIZE);
    while(!readFile.eof())
    {
        cout << info << endl;
        readFile.getline(info, SIZE);
    }
    readFile.close();
    
    ofstream myfile;
    myfile.open ("Results.txt");
    
    {
        cout << endl;      
        myfile << info << endl;
    }
    myfile.close();

The output that the program reads from Bands.txt is this:
10 0 Lady Gaga
3 7 The Full-time Retards
8 2 Solomon
9 1 MicroFuzion
5 5 Titilating Earth
2 8 Tectonic Shakers
4 6 The Freudists
7 3 Kim Jong Il
1 9 Boring Band Name
6 4 And the Other Guys

Now all i need to understand is putting that list, into another .txt file called results.txt.
Last edited on
When the right-hand side of << is a... what is info? Ah, yes, a character array... and the left side is an ofstream object (which myfile is), the array gets read out to the file that the ofstream object is representing. That's what line 33 does.

That is, assuming the ofstream is representing anything...

-Albatross
Last edited on
Topic archived. No new replies allowed.