尝试在文本文件中添加结构元素而不覆盖它

try to add structur element in a text file without overwrite it

本文关键字:元素 覆盖 结构 添加 文本 文件      更新时间:2023-10-16
void addToTextfile()
{
    Students stud[20];
    Students stdt;
    ifstream myFile;
    myFile.open("student.txt", fstream::app);
    if (myFile.is_open())
    {
        cout << "tttStudent KNumber     =>  ";
        cin >> stdt.KNumber;
        cout << "tttStudent Name        =>  ";
        cin >> stdt.StudentName;
        myFile << stdt.KNumber << stdt.StudentName << endl;
    }
    myFile.close();
}

获取错误 =>

错误

1 错误 C2678:二进制"<<":找不到采用类型为"std::ifstream"的左侧操作数的运算符(或者没有可接受的转换(

更改文件变量以使用 fstream . ifstream是给看的。 ofstream是针对 output。 fstream用于输入和输出。

operator<<用于输出。 您无法输出到输入流(不要进入出口门(。