<pre name="code" class="cpp">double* getNameValue(char *name)
{
std::ifstream file;
std::string buf, bufFromFile, beginName, endName;
int j = 0;
char *value = new char[];
double *alpha = new double[];
if (name == NULL ) {
std::cout << "name and value is invalid" << std::endl;
exit(1);
}
beginName.append("<");
beginName.append(name);
beginName.append(">");
endName.append("</");
endName.append(name);
endName.append(">");
file.open("SVM_HOG.xml");
if (!file.is_open()) {
std::cout << "error in open file ";
exit(1);
}
while (!file.eof()) {
file >> bufFromFile;
buf += bufFromFile;
}
file.close();
//std::cout << buf << std::endl;
while (buf.find(beginName) != -1)
{
int begin, end;
begin = buf.find(beginName);
end = buf.find(endName);
if (begin >= end) {
std::cout << "error in find " << name << " Item" << std::endl;
exit(1);
}
for (int i = 0; i < end - begin - beginName.length(); i++) {
value[i] = buf.at(begin + beginName.length() + i);
}
value[end - begin - beginName.length()] = '\0';
double i = atof(value);
cout << i << endl;
alpha[j] = i; j++;
buf = buf.substr(end+sizeof(endName), buf.find('\n'));
};
return alpha;
}