C++-读取配置文档

配置文件格式为:


代码:

ClassName::ChineseName()
{
    ifstream configFile;
    string filePath = "填写配置文档地址";
    configFile.open(filePath.c_str());
    string strLine;
    if (configFile.is_open())
    {
        while (!configFile.eof())
        {
            configFile >> strLine;
            size_t pos = strLine.find("=");//查找位置标签"="
            string key = strLine.substr(0, pos);//等于号左边为关键字
            string value = strLine.substr(pos + 1);//右边为值
            m_content.insert(pair<string, string>(key, value));//m_content为map容器
        }
    }
}
posted @ 2020-12-02 10:29  YellowBoss  阅读(309)  评论(0)    收藏  举报