Здравствуйте.
помогите пожалуйста с кодом, а то уже 3 день мучаюсь...
Crazy_Mapple_Reader.cpp
// Crazy_Mapple_Reader.cpp: определяет точку входа для консольного приложения.
//
#include "stdafx.h"
#include <stdlib.h>
#include "Crazy_Mapple_.h"
#include <iostream>
using namespace std;
int tmain(){
Crazy_Mapple_ Crazy_Mapple_("test.cfg");
//загружам-с
Crazy_Mapple_.load();
//вывод в std::cout
Crazy_Mapple_.show();
//читам-я
std::string val = Crazy_Mapple_.get_string("Test section", "testName");
std::cout << val << endl;
//исправлям-с
Crazy_Mapple_.put_string("test1", "12", "12");
//сохраням-с
Crazy_Mapple_.save();
//возвращает-с
return 0;
}
Crazy_Mapple_.h
//Crazy_Mapple_.h
#ifndef __Crazy_Mapple__H__
#define __Crazy_Mapple__H__
#include "stdafx.h"
#include <set>
#include <string>
#include <fstream>
#include <algorithm>
//Key structure:
// section, name, value
template<typename View>
class Crazy_Mapple_Impl{
struct Crazy_Mapple_Data{
std::string sect, name;
mutable std::string val;
Crazy_Mapple_Data(){}
Crazy_Mapple_Data(const std::string sect, const std::string &name, const std::string &val)
:sect(sect), name(name), val(val){}
struct Less{
bool operator()(const Crazy_Mapple_Data &l, const Crazy_Mapple_Data &r) const{
if(l.sect == r.sect)
return l.name < r.name;
else
return l.sect < r.sect;
}
};
};
typedef std::set<Crazy_Mapple_Data, Crazy_Mapple_Data::Less> Set;
Set data_;
string fileName_;
void put_to_stream(std::ostream &os){
string sect = "";
bool write_sect;
for (Set::iterator i = data_.begin(); i != data_.end(); ++i){
write_sect = (sect != i->sect) || (i == data_.begin());
View::write(os, write_sect, i->sect, i->name, i->val);
if(write_sect)
sect = i->sect;
}
};
public:
Crazy_Mapple_Impl(const std::string &fileName) :fileName_(fileName){};
void load(){
std::ifstream is(fileName_.c_str());
if(!is)
return;
data_.clear();
std::string sect, name, val;
while(View::read(is, sect, name, val))
put_string(sect, name, val);
};
bool save(){
std::ofstream os(fileName_.c_str());
if (!os)
return false;
else{
put_to_stream(os);
return os;
}
};
void show(){
put_to_stream(std::cout);
}
std::string get_string(const std::string §, const std::string &name){
Set::iterator i = data_.find(Crazy_Mapple_Data(sect, name, ""));
return (i != data_.end()) ? i->val : "";
}
void put_string(const std::string §,
const std::string &name, const std::string &val) {
std::pair<Set::iterator, bool> p = data_.insert(Crazy_Mapple_Data(sect, name, val));
string s(p.first->val);
if (!p.second);
p.first->val = val;
}
};
//View structure:
//[section]
//name=value
class Crazy_Mapple_CfgView{
static void skip_ws(std::istream &is){
char ch;
while(is.get(ch)){
if (!isspace(ch)){
is.putback(ch);
break;
}
}
}
public:
static bool read(std::ifstream &is, std::string §, std::string &name, std::string &val){
char ch;
skip_ws(is);
if(!is)
return false;
//read section name
is.get(ch);
if (ch == '['){
sect.erase();
while(is.get(ch) && (ch != ']'))
sect.push_back(ch);
skip_ws(is);
} else
is.putback(ch);
//read name
name.erase();
while(is.get(ch) && (ch != '='))
name.push_back(ch);
//read value
val.erase();
while(is.get(ch) && (ch != '\n'))
val.push_back(ch);
}
static void write(std::ofstream &os, bool write_sect, const std::string §,
const std::string &name, const std::string &val){
if (write_sect)
os << '[' << sect << ']' << std::endl;
os << name << "=" << val << std::endl;
}
};
typedef Crazy_Mapple_Impl<Crazy_Mapple_CfgView > Crazy_Mapple_;
#endif //__Crazy_Mapple__H__
ошибки....
------ Построение начато: проект: Crazy_Mapple_Reader, Конфигурация: Debug Win32 ------
Компиляция...
Crazy_Mapple_Reader.cpp
c:\users\username\documents\visual studio 2008\projects\crazy_mapple_reader\crazy_mapple_reader\crazy_mapple_.h(33) : warning C4346: Crazy_Mapple_Impl<View>::Crazy_Mapple_Data::Less: зависимое имя не является типом
укажите префикс 'typename' для задания типа
c:\users\username\documents\visual studio 2008\projects\crazy_mapple_reader\crazy_mapple_reader\crazy_mapple_.h(89): см. ссылку на создание экземпляров класса шаблон при компиляции "Crazy_Mapple_Impl<View>"
c:\users\username\documents\visual studio 2008\projects\crazy_mapple_reader\crazy_mapple_reader\crazy_mapple_.h(33) : error C2923: std::set: "Crazy_Mapple_Impl<View>::Crazy_Mapple_Data::Less" не является допустимым аргументом типа шаблон для параметра "_Pr"
c:\users\username\documents\visual studio 2008\projects\crazy_mapple_reader\crazy_mapple_reader\crazy_mapple_.h(36) : error C2146: синтаксическая ошибка: отсутствие ";" перед идентификатором "fileName_"
c:\users\username\documents\visual studio 2008\projects\crazy_mapple_reader\crazy_mapple_reader\crazy_mapple_.h(36) : error C4430: отсутствует спецификатор типа — предполагается int. Примечание. C++ не поддерживает int по умолчанию
c:\users\username\documents\visual studio 2008\projects\crazy_mapple_reader\crazy_mapple_reader\crazy_mapple_.h(36) : error C4430: отсутствует спецификатор типа — предполагается int. Примечание. C++ не поддерживает int по умолчанию
Журнал построения был сохранен в "
file://c:\Users\username\Documents\Visual Studio 2008\Projects\Crazy_Mapple_Reader\Crazy_Mapple_Reader\Debug\BuildLog.htm"
Crazy_Mapple_Reader — ошибок 4, предупреждений 1
помогите, пожалуйста...
а то зачет мну не получить...