2008-09-28 12 views
0

해당 기능이없는 이전 버전의 Windows CE 플랫폼 SDK를 사용 중이기 때문에 Get*Profile 기능을 사용할 수 없습니다. 너무 일반적 일 필요는 없습니다.INI 파일에서 구성 파일 항목을 읽는 방법

[section] 
name = some string 

파일을 열어 "섹션"의 존재 여부와 "이름"과 연결된 값을 확인하면됩니다. 표준 C++가 선호됩니다.

답변

2

내가 생각 해낸 무엇 :

std::wifstream file(L"\\Windows\\myini.ini"); 
if (file) 
{ 
    bool section=false; 
    while (!file.eof()) 
    { 
    WCHAR _line[256]; 
    file.getline(_line, ELEMENTS(_line)); 
    std::wstringstream lineStm(_line); 
    std::wstring &line=lineStm.str(); 
    if (line.empty()) continue; 

    switch (line[0]) 
    { 
     // new header 
     case L'[': 
     { 
     std::wstring header; 
     for (size_t i=1; i<line.length(); i++) 
     { 
      if (line[i]!=L']') 
      header.push_back(line[i]); 
      else 
      break; 
     } 
     if (header==L"Section") 
      section=true; 
     else 
      section=false; 
     } 
    break; 
     // comments 
     case ';': 
     case ' ': 
     case '#': 
     break; 
     // var=value 
     default: 
     { 
     if (!section) continue; 

     std::wstring name, dummy, value; 
     lineStm >> name >> dummy; 
     ws(lineStm); 
     WCHAR _value[256]; 
     lineStm.getline(_value, ELEMENTS(_value)); 
     value=_value; 
     } 
    } 
    } 
} 
2

당신은 Boost.Program_options 살펴 있어야합니다. 변수 맵을 채우는 parse_config_file 함수가 있습니다. 필요한 것!

관련 문제