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();