C++ 使用string一行一行讀取文件


c++ 讀取文件中的一行一行數據

通用模板:

std::ifstream in(dictpath);    
    if(!in)
    {
        std::cout << __DATE__ << " " << __TIME__
                  << __FILE__ << " " << __LINE__
                  << ": dict read error" << std::endl;
        exit(-1);
    }
    
    std::string line;
    while(getline(in, line))
    {
        std::stringstream ss(line);
        std::string key;
        int value;
        ss >> key >> value;
        dict_.push_back(make_pair(key, value));
    }
    in.close();

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM