【问题标题】:try to add structur element in a text file without overwrite it尝试在文本文件中添加结构元素而不覆盖它
【发布时间】:2016-08-02 00:15:38
【问题描述】:
void addToTextfile()
{
    Students stud[20];
    Students stdt;
    ifstream myFile;

    myFile.open("student.txt", fstream::app);

    if (myFile.is_open())
    {
        cout << "\t\t\tStudent KNumber     =>  ";
        cin >> stdt.KNumber;
        cout << "\t\t\tStudent Name        =>  ";
        cin >> stdt.StudentName;

        myFile << stdt.KNumber << stdt.StudentName << endl;

    }
    myFile.close();
}

得到错误 =>

错误 1 ​​错误 C2678:二进制“

【问题讨论】:

    标签: c++ text-files overwrite


    【解决方案1】:

    将您的文件变量更改为使用fstreamifstream 用于i输入。 ofstream 用于 o 输出。 fstream 用于输入和输出。

    operator&lt;&lt; 用于输出。您不能输出到输入流(不要进入出口门)。

    【讨论】:

      猜你喜欢
      • 2011-05-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-04-29
      • 2021-02-20
      • 2022-01-22
      • 1970-01-01
      • 2013-08-08
      相关资源
      最近更新 更多