ファイルを開いて、そこから行を読みたいと思います。ファイルには 1 行しかないので、実際にループについて心配する必要はありませんが、今後の参考のために、複数行を読み取る方法を知っておくとよいでしょう。
int main(int argc, const char* argv[]) {
// argv[1] holds the file name from the command prompt
int number = 0; // number must be positive!
// create input file stream and open file
ifstream ifs;
ifs.open(argv[1]);
if (ifs == NULL) {
// Unable to open file
exit(1);
} else {
// file opened
// read file and get number
...?
// done using file, close it
ifs.close();
}
}
どうすればいいですか?また、正常に開いたという点で、開いているファイルを正しく処理していますか?
ありがとう。