views:

1350

answers:

1

I am having some problems reading from a file. I have two header files: a and b. b is derived from a,and c is derived from b. Now i want to open a text file.

The whole format is like this:

A john

A johnee

P 123

If the first charcter is 'a' and 'p' is also there, then print the second line, else print the first line.

#include "c.h"
#include <iostream>
# include <fstream>
using namespace std;
c :: c()
{
    ifstream input;
    input.open ("abc.txt");
    ch = input.get();
    input >> ch;
    if (ch ='A')
     a* z =new a();
    else 
    input.close();
}

Can anyone give me some advice on how to accomplish this?

+2  A: 

If the first charcter is 'a' and 'p' is also there, then print the second line, else print the first line.

Could you give an example of what this program's output should look like based on the text file you have?

I did notice one thing, though:

if (ch ='A')

Change that to:

if (ch =='A')

You need to use two =s for comparisons.

Matt Blaine