another dumb error

These are the errors I get when I try to run my program using Dev C++

19 C:\Users\Erik\Documents\lab 8.cpp no match for 'operator==' in 'inData == '[''
21 C:\Users\Erik\Documents\lab 8.cpp no match for 'operator==' in 'inData == ']''

Here is my code:

#include <iostream>
#include <fstream>

using namespace std;

int main()
{
ifstream inData;
ofstream outData;

int m = 0;
int n = 0;

inData.open("input.dat");
outData.open("output.dat");

while (inData)
{
if (inData == '[')
m++;
if (inData == ']')
n++;
}

outData << "The count of the opening brackets is " << m << endl;
outData << "The count of the closing brackets is " << n << endl;


system("pause");
return 0;
}

Any help is much appreciated.
It doesn't work because you are checking
my_object == char_constant
which it won't...

You need to read characters from the string and test them against your character constants.
1
2
3
4
5
6
7
8
9
char c;
while (inData.get( c ))
  {
  switch (c)
    {
    case '[': m++; break;
    case ']': n++; break;
    }
  }

Hope this helps.
thanks it works!
Heh, can't forget that get function! ;)
Topic archived. No new replies allowed.