targetと同じ文字列を抜き出し配列として返す。CSVはポケモンの個体値のリストでtargetにポケモンの名前を渡すとそれを探す。
以下ソース
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | std::array < std::string, 9> readCSV(std::string pass, std::string target) { std::ifstream ifs(pass); if (!ifs) { std::cerr << "ファイルオープンに失敗" << std::endl; std:: exit (1); } std::string str; std::array < std::string, BaseStatusNum> data; int i = 0; while (std::getline(ifs, str)) { std::string tmp = "" ; std::istringstream stream(str); while (std::getline(stream, tmp, ',' )) { data[i] = tmp; i++; } if (data[1] == target) { break ; } else { i = 0; } } return data; } |
コメント