/** * Funkce pro získání korektních řádků ze souboru * @param string cesta k souboru * @param string* pole řetězců pro uložení obsahu souboru * @return int počet řádků při OK -3 při chybě */ int zpracovaniSouboru(string cesta, string * radky) { string line; ifstream soubor (cesta); if (soubor.is_open()) { int pocet = 0; while ( getline (soubor,line) ) { for(unsigned int i = 0; i < line.length(); i++) { if(line[i] == '#') { line.erase(line.begin()+i, line.end()); } } if (line[0] == 'h') { radky[pocet] = line; pocet++; } } soubor.close(); return pocet; } else { cerr << "Nepodařilo se otevřít soubor" << endl; return -3; } }
int gen_random(const char* filename, int n) { std::ofstream soubor(filename); int written = 0; for (int i = 0; i < n; i++) { if (!soubor.good()) return 0; else { soubor << rand() << std::endl; written++; } } soubor.close(); return written; }