非常に初歩的で単純な質問ですが、うまくいけば簡単な答えが得られます。私の問題は基本的に、次の関数パラメーターの1行のコードに帰着します。
void className::read(const string &)
{
ifstream fin;
fin.open(fname);
/* ...function code */
fin.close()
}
入力は、文字列 fname (つまりobject.read(fname)
) として main で確立されます。これを行うと、このスコープで fname が宣言されていないことがわかります。したがって、私の質問は、入力である fname を fin.open() のファイル名として使用する方法です。すでに助けてくれたすべての人に感謝し、以前の問題の説明が不十分で申し訳ありません。