Q's on File Processing

Let say i have many names in a txt file together with their scores respectively. How do I write those inputs in a new empty txt? I was thinking on using array but what if we don't know what the size of the array is? Or perhaps using eof? Please help
You do it using std::string, they can hold strings of arbitrary length.
No, i mean like let say i have these following names and scores:
John 3000
Malik 2000
Sarah 4030

How do i write these names and scores on a new txt file? ofstream?
Use a vector containing structs?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
struct scores
{
    string name;
    int score;
};

    // create a struct
    scores scoreStruct;

    // then create a vector to contain the struct
    vector< scores > scoreVector;

    // add to the struct - you'll need a loop of some sort, read from file etc.
    scoreStruct.name = "Dave";
    scoreStruct.score = 1000;

    // add to the vector
    scoreVector.push_back( scoreStruct );
Last edited on
Topic archived. No new replies allowed.