VS 2010 で C++ で単純なファイル I/O 処理プログラムを実行しようとしています。ただし、実行しようとすると、fstream に関係するエラーが発生します。このプログラムはかなり単純で、2 つのテキスト ファイルを開き、テキストを最初のファイルから 2 番目のファイルに少し変更してコピーするだけです。私は正しいロジックを持っていると確信していますが、何が間違っているのかわかりません。どんな助けでも大歓迎です。ありがとう。コードは次のとおりです。
#include<fstream>
#include<iostream>
#include<cstdlib>
using namespace std;
void file1(ifstream& in_stream, ofstream out_stream);
int main()
{
ifstream fin;
ofstream fout;
char name1[60];
cout<<"Enter the name of the input file: "<<endl;
cin>>name1;
fin.open(name1);
if(fin.fail())
{
cout<<"Failed to open Input file"<<endl;
exit(1);
}
else
{
cout<<"Input file opened successfully"<<endl;
}
char name2[60];
cout<<"Enter the name of the output file: "<<endl;
cin>>name2;
fout.open(name2);
if(fout.fail())
{
cout<<"Failed to open Output file"<<endl;
exit(1);
}
else
{
cout<<"Output file opened successfully"<<endl;
}
file1(fin, fout);
fin.close();
fout.close();
return 0;
}
void file1(ifstream& in_stream, ofstream out_stream)
{
char next;
in_stream.get(next);
while(!in_stream.eof())
{
if(next=='A')
{
out_stream<<"ABC";
}
else
{
out_stream<<next;
}
in_stream.get(next);
}
}
これは、VS 2010 で発生した正確なエラーです。
エラー 1 エラー C2248: 'std::basic_ios<_Elem,_Traits>::basic_ios': クラス 'std::basic_ios<_Elem,_Traits>' c:\program files (x86)\microsoft visual studio で宣言されたプライベート メンバーにアクセスできません10.0\vc\include\fstream 1116 1 ファイル