005
23.03.2006, 15:34 Uhr
Karldin Shinowa
Professional Noob
|
C++: |
#include<iostream> #include<fstream> #include<stdio.h> #include<string> #include"CRoom.h" string GetNextWord(ifstream&File) { string str; File>>str; return str; } void ReadRoom(ifstream &File,string strRoomname,CRoom &Room); void Check(string str,ifstream &File,CRoom &Room);
using namespace std;
int main() { ifstream File("World.txt",ios::nocreate); CRoom Room; ReadRoom(File,"Raum",Room); cout<<Room.GetDescription(); getchar(); }
void ReadRoom(ifstream&File,string strRoomname,CRoom &Room) { File.seekg(0,ios::beg); File.clear();
string strWord; Room.SetName(strRoomname); strRoomname="<"+strRoomname+">"; while(strWord!=strRoomname) { getline(File,strWord); } while(true) { strWord=GetNextWord(File); if(strWord!="#end#") { break; } Check(strWord,File,Room); } }
void Check(string str,ifstream &File,CRoom &Room) { string strTemp; int iTemp; if(str=="<description>") { getline(File,strTemp,'*'); Room.SetDescription(strTemp); } else if(str=="<viewable>") { File>>iTemp; Room.SetiViewthings(iTemp); Room.SetViewthing(File); } else if(str=="<north>") { getline(File,strTemp,'*'); Room.SetNorth(strTemp); } else if(str=="<south>") { getline(File,strTemp,'*'); Room.SetSouth(strTemp); } else if(str=="<east>") { getline(File,strTemp,'*'); Room.SetEast(strTemp); } else if(str=="<west>") { getline(File,strTemp,'*'); Room.SetWest(strTemp); } }
|
-- Ich will die Welt verbessern, doch Gott gibt mir nicht den Code. |