#include <iostream> #include <fstream> #include <sstream> #include <vector> struct Info { std::string hostname; std::string parc; }; int main() { std::ifstream file("control_ressources.txt"); if (!file) { std::cerr << "Impossible d'ouvrir le fichier !" << std::endl; return 1; } std::vector<Info> infos; std::string line; while (std::getline(file, line)) { // Vérifier si line commence par un # Info info; std::istringstream buff(line); buff >> info.hostname >> info.parc; infos.push_back(info); } for (std::vector<Info>::iterator it = infos.begin(); it != infos.end(); ++it) std::cout << "host: " << it->hostname << ", parc: " << it->parc << std::endl; return 0; }
if (line != "#") { Info info; std::istringstream buff(line); buff >> info.hostname >> info.parc; infos.push_back(info); }
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionif (line[0] != '#') { Info info; std::istringstream buff(line); buff >> info.hostname >> info.parc; infos.push_back(info); }