ifstream按行读取文件内容

bool EventComp::GetCodeDescription( std::ifstream &ifInputFile, EventCodeDesc &eventCodeDesc )
{
    eventCodeDesc.clear();
    ifInputFile.seekg(0, std::ios::beg);
    while(ifInputFile.peek() != EOF)
    {
        char buf[256] = {0};
        ifInputFile.getline(buf, 256);
        std::string strLine(buf);
        std::string::size_type nStartPos = strLine.find_first_of("0123456789");
        std::string::size_type nEndPos = strLine.find_first_of("/t", nStartPos);

        if (nStartPos != std::string::npos && nEndPos != std::string::npos)
        {
            std::string strEventCode = strLine.substr(nStartPos, nEndPos-nStartPos);
            unsigned int nEventCode = atoi(strEventCode.c_str());
            std::string strEventDesc = strLine.substr(nEndPos + 1);

            eventCodeDesc[nEventCode] = strEventDesc;
        }
    }

    return true;
}

你可能感兴趣的:(ios,String)