You are indexing into a string called foo, but you create it with a default constructor, which means that all indices are invalid (the string storage doesn't/may not exist). May-be you should append characters to the empty string.
There are also string functions that are able to find '=' characters in the string, and I think stringstream should be able to extract the portion up to the '=' character (getline with delimiter '=').
Edit:
By the way
only reads up to the first whitespace. Use getline to read whole lines.
With stringstreams you could do something like that
Code:
#include <string>
#include <sstream>
/*
Parses line, returns id and value by reference
Returns whether successful
*/
bool parse(const std::string& line, std::string& id, std::string& value)
{
std::stringstream ss(line);
return std::getline(ss, id, '=') //id read successfully
&& std::getline(ss, value) //value read successfully
&& value.find('=') == std::string::npos //value doesn't contain '='
&& ss.eof(); //nothing left to read (unneeded if line is really one line)
}