Testing a charachter line

Thnx to all who have helped me so far. Apparently, OGL can handle files, as I was told. However I am having a bit of trouble testing the contents of a line.

When I attempt to test the ‘buffer’ variable in the following code, it does not pass. Can someone please aid in explaining why? The line contents is printing to the screen just fine but I am not getting the “data confirmed” printed as should be.

    
const int MAX = 6;
char buffer[MAX];

ifstream input("test", ios::in);
input.getline(buffer, MAX);
cout << buffer << endl;

//THIS IS WHERE I AM HAVING TROUBLE
if (buffer == "hello")
{
cout << "data confirmed";
}

GAME IMAGE

  1. FYI OpenGL does not “handle files”. OpenGL is a library to allow you do to graphics. The C++ language “handles files”, you don’t need openGL to use files.
  2. This is not an OpenGL question. It’s a basic programming question
  3. You can’t compare a char array with a const char i.e
if (buffer == "hello")

that compares the address of buffer with the address of the const char array “hello”. It does not compare strings. That’s just basic C.

You either need to use the strcmp ANSI C function or convert your buffer into a std::string. i.e

  if (0 == strcmp(buffer,"hello"))

or

  string bufferStr(buffer);
  if (bufferStr == "hello")

–STU!

OK, I got this one working with this…

  

//READ SAVE FILE GAME STATE INFORMATION
int number;

ifstream input("test", ios::in);
input.seekg(count);
input >> number;
cout << number << endl;

count = count + 3;

if (number > 0)
{
cout << "data confirmed" << endl;
}

In this way I can append a series of 1’s and 0’s , each representing some state in the game (for example, a particular chest being opened or not, a certain type of armor acquired or not, ect…) to the saved game files.