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