私は、ユーザーにファイル名を尋ねて、ファイルから入力を取得し、それを別の関数で使用するメンバー関数を持っています。各関数は、charまたはcharを取ります。しかし、その機能を実行していない。私はsstreamがファイルからデータを取り出して文字化することと関係があると思いますか? sstreamを使用してファイルから要素を分離し、それらの要素をcharとして使用することは可能ですか?sstreamの質問付き文字
void My_Function::file()
{
fstream data;//file input
char filename[80];
string line;
int first;
char sec, third, fourth;
cout<<"Enter file name: \n";
cin>>fileName;
data.open(fileName);
while(getline(data,line))
{
stringstream str(line);
istringstream ins;
ins.str(line);//get line
str >> first >> sec >> third >> fourth;
switch(first)
{
case 1:
add(sec);
break;
case 2:
delete_item(sec, third);
break;
case 3:
print_everything(sec, third);
break;
case 4:
makenew(sec, third);
break;
case 5:
find(sec, third, fourth);
break;
case 0:
break;
}
}
}
は、バッファオーバーフローを防ぐために、 'fileName'文字列を作る考えてみましょう。 – outis