tags:

views:

98

answers:

3

Hello everybody, I am currently developing an application, which gets the input from a text file and proceeds accordingly. The concept is the input file will have details in this fomat

A AND B
        B OR C

Each and every line will be seperated by a blank space and the input must be taken from the text file and processed by logic. I use a TCPP compiler and i am facing problems reading the input. Please help me with the issue...

+3  A: 

Reading input a line at a time is normally done with std::getline, something like this:

std::string line;
std::ifstream infile("filename");

while (std::getline(line, infile))
    // show what we read
    std::cout << line << "\n";

If you're having trouble with things like this, you might consider looking for a (better) book on C++ than whatever you're now (hopefully) using.

Jerry Coffin
Thnk You Jerry, it worked :)
Ramprakash
A: 

Hi.. are you using headr files like:

include

or #include and you can make use of the fileobject.getline(), (do check its proper syntax.) function in C++ or for char by char use fileobject.get(ch) kind of function

mgj
+1  A: 

Following can be used straightaway:

BOOL ReadFile(CString filename)
{
    BOOL bRead = TRUE;

    std::ifstream m_strmFile;
    m_strmFile.open(filename, std::ios::in);

    char pszLine[256];
    memset(pszLine, 256, 0);

    if (m_strmFile)
    {
        // Read whatever number of lines in your file   
        for (unsigned int i = 0; i < 5/*number of lines*/; i++)
        m_strmFile.getline(pszLine, 256);
        // Do whatever you want to do with your read lines here...
    }
    else bRead = FALSE;

    return bRead;
}
Rajendra Kumar Uppal
Are the following symbols in TCPP (Turbo C Plus Plus): `BOOL`, `CString`? I believe those are Microsoft terms.
Thomas Matthews
@ ThomasYou are correct. These terms are from MS VS. Anything wrong?@ TCPP: please use bool and const char* instead of BOOL and CString or typedef bool BOOL
Rajendra Kumar Uppal