   Reading in text files
  I'm working on a method of initializing the values of base game objects. I started with an XML file and trying to use TinyXML, but, being a C++ novice, I got a little overwhelmed with the documentation. Plus, I couldn't figure out how to implement it on a schema that goes a few levels deep.Therefore, I figured I would just go with a simple text file stream. I've found some fairly straightforward examples for reading in full lines of data and working with them as one string, but I need to parse the line for individual data values. I can use the member methods of the string object to do just that, but all of the examples of streaming in text data utilizes char arrays, and I can't figure out how to mimic the string.substr() behavior with a char array. At this point, I have to read the data into a char array, copy that data to a string object and then utilize the string methods to parse the data. Silly, I know, but it's the only solution I know.Here is the code:void GameData::loadData(const char* fileName){char buffer[256];string strBuffer;ifstream ifs(fileName);Stat stat;while (!ifs.eof()){ifs.getline(buffer, 256);strBuffer = buffer;if (strBuffer.find("<Stat>") != 0){ifs.getline(buffer, 256);strBuffer = buffer;stat.statCode = strBuffer.substr(10,3);ifs.getline(buffer, 256);strBuffer = buffer;stat.statDesc = strBuffer.substr(10,20);ifs.getline(buffer, 256);strBuffer = buffer;stat.defaultValue = strBuffer.substr(10, 4);}}}How can I perform the parsing directly on the char array and avoid copying each line to a second string object first? Also, I've read that ifstream has been deprecated? I would prefer to use the newer ifstrstream if possible.* Disregard for now the fact that the Stat object will cease to exist at the end of the function.   
Quote:I can use the member methods of the string object to do just that, but all of the examples of streaming in text data utilizes char arrays, and I can't figure out how to mimic the string.substr() behavior with a char array.there is a function std::getline(stream, string) which works with std::string.e.g:std::string line;std::ifstream ifs(fileName);while(!ifs.eof()) { std::getline(ifs, line);};  You can (and should) use the return value of std::getline as the loop condition. Otherwise, you will process the final record twice. Remember, std::fstream::eof() only works once there has been a past-the-end read, it will return true otherwise:std::string line;std::ifstream ifs(fileName);while(std::getline(ifs, line)){   // ...}That said, unless you are using a XML parser, I wouldn't represent the data in XML. You could go with a simple line based delimited format, such as name = value. This would be far easier to parse than trying to hack up a limited XML parser.   ;  Thanks folks. That worked. I do plan to change the XML data file to pipe-delimited now.;  Ok. One more question. What's wrong with the following:stat.defaultValue = strtol(strBuffer.substr(10, 4)); // stat.default is a longI get the following error:"IntelliSense: no suitable conversion function from "std::basic_string<char, std::char_traits<char>, std::allocator<char>>" to "const char *" exists"   ;  std::string::substr() returns a std::string. strtol() expects a const char *. To get a const char * for a std::string, use the .c_str() member function.   ;  Thanks. Works now.