I have a piece of code that should open a text file (.ini) with a variable on every line, followed by its value. The code should read a variable name, recognize it and set the appropriate variable in my code to the value stored in the file.
Here is the code:
The problem is that it seems that I can't use a stream with my string ("error C2679: binary '>>' : no operator found which takes a right-hand operand of type 'std::string' (or there is no acceptable conversion)"). I tried to use a char array but that doesn't seem to work either. Is something like this possible, or should I use regular if/else with strcmp?Code:void IniParser::Parse(char *fileName) { ifstream iniFile (fileName); if(!iniFile.is_open()) { std::cout << "Could not open ini file: " << fileName << std::endl; return; } //char inputStr[128]; string inputStr; while(iniFile >> inputStr) { switch (inputStr) { case "blah": std::cout << "variable blah was read in the ini file" << std::endl; //TODO: Read & set variable break; default: std::cout << "Unknown variable encountered while reading"<< *fileName << std::endl; break; } } }