My program wont compile because of this one function, can someone explain to me why it is says "forbids comparison between pointer and integer" Any help would be appreciated

void ReadBitPattern (ifstream& infile)
{
    int x;
    x = cin.get();

    if(cin.get() == "0")
    {
        for (int index = 0; index < PatternSize; index++) 
        {
            OperandArray bitArray[index] = '0';
        }
    }
    else 
    {
     for (int index = 0; index < PatternSize; index++)
     {
         OperandArray bitArray[index] = '1';
     }
    }



}

cin.get returns an istream reference not an int. if you want to get an single character than you would do

char ch;
cin.get(ch);
// now ch has 1 letter from the input stream

so could I put this? Essentially im trying to convert a string that im reading in from a file into a character, im kind of confused:

    char ch;


    if(cin.get(ch) == "0")

for a single char you want to use

//...
char ch;
cin.get(ch);

if (ch == '0')
    //...
//...

That worked but quick question: As of now the function reads the first bit and sets the array to 0 or 1, but I actually want it to just print the bits that are in the file that is being read in. What am I doing wrong?

void ReadBitPattern (ifstream& infile)
{
    char ch;
    cin.get (ch);

    if(ch == '0')
    {
        for (int index = 0; index < PatternSize; index++) 
        {
            OperandArray bitArray[index] = '0';
        }
    }
    else 
    {
        for (int index = 0; index < PatternSize; index++)
        {
            OperandArray bitArray[index] = '1';
        }
    }



}

With the function the way it is now it runs like this:
(Example) if the first bit in the file is 0 then it sets the array to 00000000

to have it keep reading you need to put the code inside of a loop. something like this

//...
char ch;

while(cin.get(ch)) // loop until all input is processed
{
    if(ch == '0')
    {
        for (int index = 0; index < PatternSize; index++) 
        {
            OperandArray bitArray[index] = '0';
        }
    }
    else 
    {
        for (int index = 0; index < PatternSize; index++)
        {
            OperandArray bitArray[index] = '1';
        }
    }
}
//...
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.