Type: Note
用 stringstream by 特定字元切割 ex: ':'
std::ifstream infile("file.txt"); if (!infile.is_open()) return; std::string line; while (std::getline(infile, line)) { std::stringstream ss(line); std::string key, val; std::getline(ss, key, ':'); std::getline(ss, val, ':');用 istringstream by token (空白) 切割
while (std::getline(infile, line)) { std::string key, val; istringstream iss(line); std::vector<std::string> tokens; copy(std::istream_iterator<std::string>(iss), std::istream_iterator<std::string>(), back_inserter<vector<std::string> >(tokens)); if (tokens.size() != 2) continue; key = tokens[0]; val = tokens[1];
沒有留言:
張貼留言