尝试在文本文件中添加结构元素而不覆盖它
try to add structur element in a text file without overwrite it
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<<
用于输出。 您无法输出到输入流(不要进入出口门(。
相关文章:
- Mongodb c++驱动程序:如何查询元素的数组
- 将数组作为参数传递给函数安全吗?作为第三方职能部门,可以探索他们想要的之外的其他元素
- 使用strcpy将char数组的元素复制到另一个数组
- 使用不带参数的函数访问结构元素
- 给定n个元素的m个集合.在C++中找到出现在最大集合数中的元素
- C++如何通过用户输入删除列表元素
- lower_bound()返回最后一个元素
- 基于多个条件处理地图中的所有元素
- 当将多个TypedArrayContents数组加载到V8数组中时(数组数组)时,最后一个元素将覆盖所有元素
- 覆盖数组元素时如何调用构造函数
- 在阵列中没有覆盖元素
- c ++ 我的 char* 数组被最后一个添加的元素覆盖
- 使用 char **,其中新元素覆盖以前的元素
- 尝试在文本文件中添加结构元素而不覆盖它
- 如何覆盖其他窗口应用程序的元素?
- 在 stl 映射中插入新项目时,将覆盖到第一个元素
- vector元素被覆盖
- 映射写入失败:无法覆盖第一个元素
- 字符串拆分为矢量<字符*>覆盖矢量元素
- 一旦满足指定容量,覆盖优先级队列末尾的元素