Commit 473ace78 by Szeberényi Imre

v0

parent 90b5b05d
1
2
3
4jhjh
12345678
6
7
8
#include <iostream>
#include <fstream>
/// Bugyuta kd, ami megszmolja a sorok szmt.
/// Ha van 9 karakternl hosszabb sora, akkor hibt dob.
int szamol(const char *f) {
std::ifstream inp(f); /// megnyits
int n = 0;
while (inp.good()) { /// file feldolgozsa
char buf[9+1];
inp.getline(buf, 9+1);/// sorvegig, de max 9 kar.
if (inp.eof()) break;
if (inp.fail()) {
inp.close(); /// lezrs hiba esetn
throw "baj_van";
}
n++;
}
inp.close(); /// lezrs normal esetn
return (n);
}
struct Inputstream : std::ifstream {
Inputstream(const char *f) :std::ifstream(f) {}
~Inputstream() { close(); }
};
int szamol2(const char *f) {
Inputstream inp(f); /// megnyits
int n = 0;
while (inp.good()) { /// file feldolgozsa
char buf[9+1];
inp.getline(buf, 9+1);/// sorvegig, de max 9 kar.
if (inp.eof()) break;
if (inp.fail()) throw "baj_van";
n++;
}
return (n);
}
int main() {
try {
std::cout << szamol2("file.txt") << std::endl;
} catch (...) {
std::cout << "baj van\n" << std::endl;
}
}
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_project_file>
<FileVersion major="1" minor="6" />
<Project>
<Option title="orszem" />
<Option pch_mode="2" />
<Option compiler="gcc" />
<Build>
<Target title="Debug">
<Option output="bin/Debug/orszem" prefix_auto="1" extension_auto="1" />
<Option object_output="obj/Debug/" />
<Option type="1" />
<Option compiler="gcc" />
<Compiler>
<Add option="-g" />
</Compiler>
</Target>
<Target title="Release">
<Option output="bin/Release/orszem" prefix_auto="1" extension_auto="1" />
<Option object_output="obj/Release/" />
<Option type="1" />
<Option compiler="gcc" />
<Compiler>
<Add option="-O2" />
</Compiler>
<Linker>
<Add option="-s" />
</Linker>
</Target>
</Build>
<Compiler>
<Add option="-Wall" />
<Add option="-fexceptions" />
</Compiler>
<Unit filename="main.cpp" />
<Extensions>
<lib_finder disable_auto="1" />
</Extensions>
</Project>
</CodeBlocks_project_file>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment