referncing an int using boost

im introducing boost in my code and would like to make the datapushback that occurs on line 110 to pushback the int "points" instead of "1, 2", id also like for line 111 to push back a value that will become know as "total score", but as of the moment I have not implemented a total score system that will add all of the points a player has gathered so far, as I am not sure how I would do this

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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <ctime>
#include <cstdlib>
#include <cctype>
#include <boost/serialization/list.hpp>
#include <boost/thread.hpp>
#include <boost/asio.hpp>
//needed for boost networking
#include <boost/archive/text_oarchive.hpp>
#include <boost/archive/text_iarchive.hpp>

class scores {
    int best, previous;
public:
    scores(){}
    scores(int best, int previous) :best(best), previous(previous){}
    friend class boost::serialization::access;
    template<class Archive>
    void serialize(Archive& ar, const unsigned int version)
    {
        ar& best;
        ar& previous;
    }
};

using namespace std;
int points;
void question(const std::string& fname)
{
    vector<string> lines;
    ifstream file(fname);


    if (!file) {
        cout << "Cannot open file " << fname << '\n';
        return;
    }

    for (string line; getline(file, line); lines.push_back(line));
    const auto random_number{ rand() % lines.size() };
    const auto word{ lines[random_number] };
    const auto codes{ new int[word.length()] {} };

    for (size_t i = 0; i < word.length(); ++i)
        if (isalpha(static_cast<unsigned char>(word[i]))) {
            codes[i] = std::tolower(static_cast<unsigned char>(word[i])) - 'a' + 1;
            cout << codes[i] << ' ';
        }
    string answer;
    cout << "\nPlease input your answer (no capitals, no spaces): ";
    cin >> answer;
    cout << word;
    if (answer == word) {
        cout << "\nCorrect!\n\n";
        points++;
    }
    else
        cout << "\nIncorrect :(\n\n";
}
struct Quiz {
    string fname;
    string title;
    string catnum;
};
int main()
{
    const Quiz qz[]{ {"Premier_League_Teams.txt", "\nPremier League Football Teams!\n", "first"},
        {"Premier_League_Teams.txt", "\nPremier League Football Teams!\n", "second"},
        {"Hobbit_Characters.txt", "\nHobbit Characters\n", "third"},
        {"Hobbit_Characters.txt", "\nHobbit Characters\n", "fourth"},
        {"South_American_Countries.txt", "\nSouth American Countries\n", "final"} };
    //these lines of code identify the text files from the stored folder, and also output the name of the round, as well as its position in the queue using the strings above

    srand(static_cast<unsigned int>(time(nullptr)));
    //seeds the random number generator and ensures it is not affected by previous launching of the code
    cout << "Epic quiz\n\n\n";
    cout << "The objective of this round is to unscramble the coded word.\n";
    cout << "You will be given the category as the clue\n";
    cout << "and you have to type out what you believe the answer to be, with a capital letter\n\n";
    //introductory text for the user to read

    string Name;
    cout << "But First, Enter your first name: ";
    getline(cin, Name);

    cout << "\nWelcome contestant " << Name << ". Are you ready to begin the quiz?\n";
    cout << "Please type yes to continue (case sensitive): ";
    string respond;
    cin >> respond;
    if (respond != "yes") {
        cout << "Maybe next time!\n";
        return 0;
        //this adds a degree of playability to the game, offering a quit game button, to increase immersion and the user experience
    }
    cout << "Good luck!\n";

    for (const auto& quiz : qz) {
        cout << "The " << quiz.catnum << " category is...\n" << quiz.title << '\n';
        //this tells the user the number of the category we are on, and what the category is
        question(quiz.fname);
        //this loads the question from the quiz data structure

        cout << Name << ", your score is " << points << " out of 5!\n";
        //after each answer is submitted the user is told their current score out of the total amount of questions

        std::list<scores> data;
        data.push_back(scores(1, 2));
        data.push_back(scores(3, 4));
        {
            std::ofstream out("scores.txt");
            boost::archive::text_oarchive arch(out);
            arch << data;
        }
    }
}



these are the specifically relevant lines

1
2
3
4
5
6
7
8
9
        cout << Name << ", your score is " << points << " out of 5!\n";

        std::list<scores> data;
        data.push_back(scores(1, 2));
        data.push_back(scores(3, 4));
        {
            std::ofstream out("scores.txt");
            boost::archive::text_oarchive arch(out);
            arch << data;


i would like for it to look something more like this, but this does not work

1
2
3
4
5
6
7
8
9
        cout << Name << ", your score is " << points << " out of 5!\n";

        std::list<scores> data;
        data.push_back(scores(points));
        data.push_back(scores(totalscore));
        {
            std::ofstream out("scores.txt");
            boost::archive::text_oarchive arch(out);
            arch << data;

Last edited on
when i try and make the first data push back
 
        data.push_back(scores(1, 2));

look like
 
        data.push_back(scores(points));

the error looks like "no instance of constructor "scores::scores" matches the argument list"
Last edited on
Well yeah, the error message is telling you exactly the problem..
How many arguments are you trying to pass to scores() ? - One
Do you have a constructor that takes exactly one argument ? - NO
18
19
   scores(){}
    scores(int best, int previous) :best(best), previous(previous){}

You have a default constructor that takes no arguments and an explicit constructor that takes exactly two arguments,

Last edited on
sorry im still fairly new to boost on C++, how do I solve this? I'm not sure what I have to add
You're trying to call a call a constructor that takes one argument but you don't have one.
You need to add a constructor that takes one argument.
 
scores (int points);

Last edited on
so I would have to have a separate constructor for best? if I'm understanding right
now im getting an error ive not encountered before, something called a "linker tools error", is that something wrong with the boost linker or is that coincidence its the same word
You haven't shown the error message, so can't tell you.
Topic archived. No new replies allowed.