Hi. I'm trying to access some data in a List using an Iterator, but I'm getting an error message:

#include <iostream>
#include <list>
#include <string>
#include <iomanip>

using namespace std;

/**
 * Global Variables
 */
int printer;
int disk;
int cd;
int num;
string k;
int pmem, plen;
int dmem, dlen;
int cmem, clen;
string dname, pname, cname, drw, prw, crw;


class PCB
{
public:
    PCB() : pid( 0 ), filename ( "InitialString" ), memoryLocation ( 0 ), rw ( "InitialString" ) { }
    void setPid( int p );
    int getPid() const;
    int incrementPid();
    int decrementPid();
    void setFilename( string f );
    string getFilename() const;
    void setMemoryStart( int m );
    int getMemoryStart() const;
    void setFileLength( int l );
    int getFileLength() const;
    void setRW( string r );
    string getRW() const;
    void screen();
    void runningPrompt() const;
    list<PCB> readyQueue;
    list<PCB>::iterator g;
    list<PCB> diskQueue;
    list<PCB> printerQueue;
    list<PCB> cdQueue;
private:
    int pid;
    string filename;
    int memoryLocation;
    string rw;
    int fileLen;
};

/**
* This runningPrompt Function receives input from the keyboard regarding processes
*/
void PCB::runningPrompt() const
{
    cout << "You may enter a command or type 'exit' to exit the system." << endl;
    PCB initialProcess;
    while (k != "exit")
    {
        cout << "Please enter command: ";
        cin >> k;
        if ( k[0] == 'A' )
        {
            cout << "New Process created." << endl;
            initialProcess.incrementPid();
            cout << "Pid is " << initialProcess.getPid() << endl;
            initialProcess.readyQueue.push_back( initialProcess );
        }
        if( k[0] == 't' )
        {
            cout << "Process terminating." << endl;
            cout << "Process has entered CPU." << endl;
        }
        if( k[0] == 'S' )
        {
            initialProcess.screen();
        }
        if( k[1] == '1' )
            num = 1;
        if( k[1] == '2' )
            num = 2;
        if( k[1] == '3' )
            num = 3;
        if( k[1] == '4' )
            num = 4;
        if( k[1] == '5' )
            num = 5;
        if( k[1] == '6' )
            num = 6;
        if( k[1] == '7' )
            num = 7;
        if( k[1] == '8' )
            num = 8;
        if( k[1] == '9' )
            num = 9;
        if ( k[0] == 'd' )
        {
            if( !initialProcess.readyQueue.empty() )
            {
                cout << "This is a system call requesting Disk " << num << endl;
                cout << "What is the filename? Please enter it: " << endl;
                cin >> dname;
                initialProcess.setFilename( dname );
                cout << "What is the starting location in memory? Please enter it:" << endl;
                while( ( ! ( cin >> dmem ) ) || dmem < 0  )
                {
                    cout << "That was not a positive integer...\nTry again: ";
                    cin.clear();
                    cin.ignore( numeric_limits<streamsize>::max(), '\n' );
                }
                initialProcess.setMemoryStart( dmem );
                cout << "Please enter the length of your file in an integer value:" << endl;
                while( ( ! ( cin >> dlen ) ) || dlen < 0 )
                {
                    cout << "That was not positive integer...\nTry again: ";
                    cin.clear();
                    cin.ignore( numeric_limits<streamsize>::max(), '\n' );
                }
                initialProcess.setFileLength( dlen );
                cout << "Please enter r for read or w for write" << endl;
                cin >> drw;
                while( ! ( drw == "r" || drw == "w" ) )
                {
                    cout << "Please enter a r or a w" << endl;
                    cin >> drw;
                }
                initialProcess.setRW( drw );
                initialProcess.diskQueue.push_back( initialProcess );
                initialProcess.decrementPid();
                initialProcess.readyQueue.pop_front();
            }
            else
            {
                cout << "There are no processes in the ready queue." << endl;
            }
        }
        if ( k[0] == 'p' )
        {
            cout << "This is a system call requesting printer: " << num << endl;
            cout << "What is the filename? Please enter it: " << endl;
            cin >> pname;
            initialProcess.setFilename( pname );
            cout << "What is the starting location in memory? Please enter it:" << endl;
            while( ( ! ( cin >> pmem ) ) || pmem < 0  )
            {
                cout << "That was not a positive integer...\nTry again: ";
                cin.clear();
                cin.ignore( numeric_limits<streamsize>::max(), '\n' );
            }
            initialProcess.setMemoryStart( pmem );
            cout << "Please enter the length of your file in an integer value:" << endl;
            while( ( ! ( cin >> plen ) ) || plen < 0 )
            {
                cout << "That was not positive integer...\nTry again: ";
                cin.clear();
                cin.ignore( numeric_limits<streamsize>::max(), '\n' );
            }
            initialProcess.setFileLength( plen );
            cout << "Please enter r for read or w for write" << endl;
            cin >> prw;
            while( ! ( prw == "r" || prw == "w" ) )
            {
                cout << "Please enter a r or a w" << endl;
                cin >> prw;
            }
            initialProcess.setRW( prw );
            initialProcess.printerQueue.push_back( initialProcess );
        }
        if ( k[0] == 'c' )
        {
            cout << "This is a system call requesting CD/RW: " << num << endl;
            cout << "What is the filename? Please enter it: " << endl;
            cin >> cname;
            initialProcess.setFilename( cname );
            cout << "What is the starting location in memory? Please enter it:" << endl;
            while( ( ! ( cin >> cmem ) ) || cmem < 0  )
            {
                cout << "That was not a positive integer...\nTry again: ";
                cin.clear();
                cin.ignore( numeric_limits<streamsize>::max(), '\n' );
            }
            initialProcess.setMemoryStart( cmem );
            cout << "Please enter the length of your file in an integer value:" << endl;
            while( ( ! ( cin >> clen ) ) || clen < 0 )
            {
                cout << "That was not positive integer...\nTry again: ";
                cin.clear();
                cin.ignore( numeric_limits<streamsize>::max(), '\n' );
            }
            initialProcess.setFileLength( clen );
            cout << "Please enter r for read or w for write" << endl;
            cin >> crw;
            while( ! ( crw == "r" || crw == "w" ) )
            {
                cout << "Please enter a r or a w" << endl;
                cin >> crw;
            }
            initialProcess.setRW( crw );
            initialProcess.cdQueue.push_back( initialProcess );
        }
        if( k[0] == 'D' )
        {
            if( !initialProcess.diskQueue.empty() )
            {
                for( int i = 0; i < initialProcess.diskQueue.size(); i++ )
                {
                     initialProcess.diskQueue.pop_front();
                }
            }
            else
            {
               cout << "The disk queue is empty. " << endl; 
            }
        }
    }
}

void PCB::setPid(int p)
{
    pid = p;
}

int PCB::getPid() const
{
    return pid;
}

int PCB::incrementPid()
{
    pid++;
}

void PCB::setFilename( string f )
{
    filename = f;
}

string PCB::getFilename() const
{
    return filename;
}

void PCB::screen()
{
    cout << "Taking Snapshot." << endl;
    cout << "Please select r, d, p, or c." << endl;
    string rpdc;
    cin >> rpdc;
    while ( ! ( rpdc[0] == 'r' || rpdc[0] == 'p' || rpdc[0] == 'd' || rpdc[0] == 'c' ) )
    {
        cout << "Please enter r, p, d, or c. Thank you." << endl;
        cout << "Enter selection" << endl;
        cin >> rpdc;
    }
    if( rpdc[0] == 'r' )
    {
        cout << left << setw(9) << "PID" << left << setw(14) << "Filename"
        << left << setw(14) << "Memstart" << " R/W" << endl; 
        if( !readyQueue.empty() )
        {
            //for( int i = 0; i < readyQueue.size(); i++ )
            //{
            for( g = readyQueue.begin(); g != readyQueue.end(); g++ )
            {
                cout << left << setw(0) << "" << getPid() << left << setw(4) <<  " "
                << left << setw(14) << " " << left << setw(14) <<  " "
                << left << setw(14) << " " << " " << endl;
            }
            //}
        }
        else
        {
                cout << left << setw(0) << "" << "0" << left << setw(4) <<  " "
                << left << setw(14) << " " << left << setw(14) <<  " "
                << left << setw(14) << " " << " " << endl;
        }
    }
    if( rpdc[0] == 'p' )
    {
        cout << left << setw(9) << "PID" << left << setw(14) << "Filename"
        << left << setw(12) << "Memstart" << left << setw(14) << "FileLen" << " R/W" << endl;
        if( !printerQueue.empty() )
        {
            for( int i = 0; i < printerQueue.size(); i++ )
            {
                cout << left << setw(0) << "--p" << i+1 << left << setw(4) <<  " "
                << left << setw(14) << printerQueue.front().getFilename() << left << setw(14) <<  printerQueue.front().getMemoryStart()
                << left << setw(14) << printerQueue.front().getFileLength() << printerQueue.front().getRW() << endl;
            }
        }
        else
        {
                cout << left << setw(0) << "" << "0" << left << setw(4) <<  " "
                << left << setw(14) << " " << left << setw(14) <<  " "
                << left << setw(14) << " " << " " << endl;
        }
    }
    if( rpdc[0] == 'd' )
    {
        cout << left << setw(9) << "PID" << left << setw(14) << "Filename"
        << left << setw(12) << "Memstart" << left << setw(14) << "FileLen" << " R/W" << endl;
        if( !diskQueue.empty() )
        {
            for( g = diskQueue.begin(); g != diskQueue.end(); g++ )
            {
                cout << left << setw(0) << "--d" << diskQueue.size()<< left << setw(4) <<  " "
                << left << setw(14) << *g.getFilename() << left << setw(14) <<  *g.getMemoryStart()
                << left << setw(14) << *g.getFileLength() << *g.getRW() << endl;
            }
        }
        else
        {
                cout << left << setw(0) << "" << "0" << left << setw(4) <<  " "
                << left << setw(14) << " " << left << setw(14) <<  " "
                << left << setw(14) << " " << " " << endl;
        }
    }
    if( rpdc[0] == 'c' )
    {
        cout << left << setw(9) << "PID" << left << setw(14) << "Filename"
        << left << setw(12) << "Memstart" << left << setw(14) << "FileLen" << " R/W" << endl;
        if( !cdQueue.empty() )
        {
            for( int i = 0; i < cdQueue.size(); i++ )
            {
                cout << left << setw(0) << "--c" << i+1 << left << setw(4) <<  " "
                << left << setw(14) << cdQueue.front().getFilename() << left << setw(14) <<  cdQueue.front().getMemoryStart()
                << left << setw(14) << cdQueue.front().getFileLength() << cdQueue.front().getRW() << endl;
            }
        }
        else
        {
                cout << left << setw(0) << "" << "0" << left << setw(4) <<  " "
                << left << setw(14) << " " << left << setw(14) <<  " "
                << left << setw(14) << " " << " " << endl;
        }
    }
}

int PCB::decrementPid()
{
    pid--;
}


void PCB::setMemoryStart( int m )
{
    memoryLocation = m;
}

int PCB::getMemoryStart() const
{
    return memoryLocation;
}


void PCB::setFileLength( int l )
{
    fileLen = l;
}

int PCB::getFileLength() const
{
    return fileLen;
}


void PCB::setRW( string r )
{
    rw = r;
}

string PCB::getRW() const
{
    return rw;
}


int main ()
{

    PCB p;
    p.runningPrompt();
    return 0;
}

The error message starts at line 310. This is the code causing the error:

<< left << setw(14) << *g.getFilename() << left << setw(14) <<  *g.getMemoryStart()

This is the first error message:

310 C:\Users\...\iterator1.cpp 'struct std::_List_iterator<PCB>' has no member named 'getFilename' 

Thank you.

iterators are pointers and need the -> operator not the dot operator

            cout << left << setw(0) << "--d" << diskQueue.size() << left << setw(4) << " "
                << left << setw(14) << g->getFilename() << left << setw(14) << g->getMemoryStart()
                << left << setw(14) << g->getFileLength() << g->getRW() << endl;
commented: Excellent help! +0

Thanks Ancient Dragon. It worked!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.