Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

C++ Vectors

Name: Anonymous 2011-05-25 8:55

I got a function that adds to the vector which is

scores = new vector<string>;

void addToVec(string name, int score)
{
    scores->push_back(name);
    scores->push_back((char*)score);
    addToFile(scores);
}

then i want to add it to a output file with

void addToFile(vector<string> scores)
{
    ofstream outFile(SCORES_FILE, ios::app);
   
    if(outFile.fail()) {
        cout << "Could not write to scores file, exiting program" << endl;
        exit(1);
    }
   
    for (int i = 0; i < scores.size(); i++) {
        outFile << scores[i];
        outFile << " ";
    }
   
    outFile.close();
}

But i keep getting a "no matching function for the call 'addToFile(std::basic_string...etc etc"

My code all wrong?

Name: Anonymous 2011-05-25 11:20

Scrapped all that other rubbish. Is this better?

Class::Class()
{
scores = new vector<int>;
map<string, vector<int> > player;
map<string, vector<int> >::iterator iterMap;
vector<int>::iterator iterVec;
}

void Class::addToVec(string name, int score)
{
    scores->push_back(score);
    iterMap = player.find(name);
   
    iterVec = (*iterMap).second.begin();
    iterMap->second.insert(iterVec, score);
   
    printToFile(name, &player[name]);
}

void Class::printToFile(string name, vector<int> *scores)
{
    ofstream outFile(SCORES_FILE, ios::app);
   
    if(outFile.fail()) {
        cout << "Could not write to scores file, exiting program" << endl;
        exit(1);
    }
   
    for(iterMap = player.begin(); iterMap != player.end(); iterMap++) {
        outFile << name << " - ";
        for(int i = 0; i < scores.size(); i++) {
            outFile << scores[i] << endl;
        }
    }
    outFile.close();
}

Only problem now is the loop for printing to the file. Any help?
Well i don't know if its the only problem what i can run it atm.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List