Hello everyone,

I'm having a problem with an assignment that I'm not sure how to fix I'm getting the following error:

accountdb.cpp:55: error: cannot convert std::string to const char* for argument 1 to int strcmp(const char*, const char*)

Here is my header file:

#include "account.h"
#include <string>

class AccountDB
                        Account AccountArray[30];
                        int ObjectsStored;
                        AccountDB(const char*);
                        void print () const;
                        void sortAccounts();


And here is where the error is comming from (accountdb.cpp):

#include "account.h"
#include "accountdb.h"
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <string>
#include <cstring>
#include <fstream>

using namespace std;

                ObjectsStored = 0;

AccountDB::AccountDB(const char* accountdb)
                ifstream inFile;
                inFile.open(accountdb, ios::binary);
                if (!inFile)
                        cout << "Unable to open file accountdb" << endl;
                inFile.read((char*) this, sizeof(AccountDB));


void AccountDB::print() const

        cout << "Account Database Listing" << endl << endl;

        for (int i = 0; i < ObjectsStored; i++)
        cout << endl;

void AccountDB::sortAccounts()
        int i, j;
        Account bucket;

        for (i = 1; i < ObjectsStored; i++)
                bucket = AccountArray[i];

                for (j = i; (j > 0) && (strcmp(AccountArray[j - i].getAccountNumber(), bucket.getAccountNumber() )> 0); j --)
                        AccountArray[j] = AccountArray[j - 1];
                        AccountArray[j] = bucket;

The sortAccounts method should sort ACCOUNTS in ascending order. I'm getting an error and I'm not sure how to fix and I've been stuck for a while now. Anyone know how I can fix it? I tried using c_str but I probably used it wrong and it ended up giving me more errors. Any way to do it while using strcmp?

Thank you for your help.

Did you try

strcmp(AccountArray[j - i].getAccountNumber().c_str(), bucket.getAccountNumber().c_str() )

This should work but you could compare strings directly.