First, your "ignore" usage is wonky: .ignore() skips stuff for the specified number of characters, or until the first appearance of the specified single character, whichever comes first. The second argument is a char argument, i.e. something specified in single quotes which is supposed to be a single character - your compiler should at least warn you for putting 'roomn' like that. Anyway, as it is, it will do nothing, because it will succeed in ignoring 0 characters right away, so that "comes first". But as it stands, you don't *want* to .ignore() anything at that point anyway, so the best thing is to just take that line out.
Also, you seem to have a fundamental misunderstanding of how C++ variables work. The variable names are not data of any sort, and do not exist in the compiled code. Thus, you cannot say 'roomn' and expect it to refer to the contents of a variable named roomn; it refers to that text instead (notwithstanding the single-quote issue).
Anyway, what you should do is: First, get acquainted with std::string; it will save you a hell of a lot of trouble down the road. It won't limit your text length, won't cause any memory management issues, and won't mess up when you try to pass it back from a function, the way a character array would.
Second, what you need to do is read the file as a series of entries. Each time, look at the 'name', and if it matches, then we can proceed.
Third, don't use globals when you can easily handle the problem by passing the value back as a return value. Here, "ingame" can be local to main(), and we can set it to a return value that we get from printloc().
#include <fstream>#include <iostream>#include <string> // for std::stringusing namespace std;// As I said, we can use the return value to set 'ingame'.// However, it's best not to mix the finding and output tasks together.// So, let's build a string that represents what we need to output, and// return that. If we can't find the room name, we'll return an empty string.string readDescription(const string& desiredRoom) { ifstream gamedata("simpletext.gam"); string name, title, desc; // Keep reading until the name matches the desired room name. while(name != desiredRoom && !gamedata.eof()) { // std::string lets us compare strings like that. Character arrays don't. // To read a whole line into a std::string, we must use this free function // instead (rather than the ifstream member function): getline(gamedata, name); getline(gamedata, title); getline(gamedata, desc); // And now we will skip over the blank line that separates entries: gamedata >> ws; // assumes it will be blank. There are other ways, too. } // When we get here, either the name matches the desired room name (and // the title and desc have already been read for that room), or the file // reached the end (name not found). if (gamedata.eof()) return ""; // The "" makes a char*, but it will be // implicitly converted by assignment to the return value. // Otherwise, we have the data we need. // We can now build up a string consisting of the title and desc. return title + "\n " + desc; // That's another thing you can't do with character arrays.}// Having the input as a local variable here doesn't really help; we want to// communicate it back so we can use it.string readinput() { cout << "\n> "; string input; getline(cin, input); return input;}int main() { string roomDescription = ""; string userInput; // Previously, we ended the loop unconditionally, because printloc() would // always set ingame to false. Now I'm doing it so that we end the loop almost // every time; i.e. as long as we are able to read the room entry (such that // roomDescription becomes non-empty, falsifying the loop condition). You // probably want it to work the other way around, though, eventually. while(roomDescription == "") { // Try to find and show the data for roomB roomDescription = readDescription("roomB"); cout << roomDescription; userInput = readinput(); } }
There are still lots of problems (in particular, you really don't want to re-read the whole file, every time through) and lots of work to do, but this should get you on the right track. :)