文件无法将准确的数据写入文本文件
File failing to write accurate data to a text file
//My name is Chris Salazar and this is Assignment 7. This program is an upgraded grading program
#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
using namespace std;
const int STUDENTS = 100;
struct studentType
{
string fname;
string lname;
int test1;
int test2;
int test3;
int test4;
double average;
char grade;
};
void initRecords(studentType students[]);
int readData(studentType students[]);
double getStudentAverageGrade(studentType aStudent);
char getGrade(double average);
void sortRecords(studentType students[], int totalStudents);
void swapRecords(studentType& aStudent, studentType& bStudent);
void writeRecords(studentType students[], int totalStudents);
void drawLine(ofstream& fout, char ch, int width);
void checkRecords(studentType students[], int totalStudents);
int findMax(int, int);
int findMin(int, int);
int main(int argc,char** argv)
{
int totalStudents = 0;
studentType students[STUDENTS];
initRecords(students);
totalStudents = readData(students);
checkRecords(students, totalStudents);
sortRecords(students, totalStudents);
cout << "after sorting..." << endl;
checkRecords(students, totalStudents);
writeRecords(students, totalStudents);
cout << "Done!" << endl;
system("pause");
return 0;
}
int readData(studentType students[])
{
ifstream fin;
string fileName;
int i;
cout << "Enter filename: ";
cin >> fileName;
fin.open(fileName);
//if (!fin)
//{
// cout << "FILE NOT PRESENT" << endl;
// cin.get();
// cin.get();
// exit(0);
//}
i = 0;
while (fin && i < STUDENTS)
{
fin >> students[i].fname >> students[i].lname >> students[i].test1 >> students[i].test2 >> students[i].test3 >> students[i].test4;
if (!fin)
break;
students[i].average = getStudentAverageGrade(students[i]);
students[i].grade = getGrade(students[i].average);
i += 1;
}
fin.close();
return i;
}
void writeRecords(studentType students[], int totalStudents)
{
string fileName;
int i = 0;
ofstream fout;
cout << "Enter a file name to write to: " << endl;
getline(cin, fileName);
cin >> fileName;
fout.open(fileName);
while (fout && i < STUDENTS)
{
fout << STUDENTS << students[11].fname << " ";
fout << STUDENTS << students[11].lname << " ";
fout << STUDENTS << students[11].test1 << " ";
fout << STUDENTS << students[11].test2 << " ";
fout << STUDENTS << students[11].test3 << " ";
fout << STUDENTS << students[11].test4 << " ";
//<< students[i].lname << students[i].test1 << students[i].test2 << students[i].test3 << students[i].test4;
i += 1;
}
}
我的"writeRecords"函数没有返回任何准确的信息,而是返回随机数字/字母。这不是我的全部代码,并且被削减以减少任何寻求帮助的人阅读。任何帮助将不胜感激。
U 函数声明:
void sortRecords(studentType students[], int totalStudents);
与您的函数定义不匹配:
void sortRecords(studentType students, int totalStudents[])
相关文章:
- 从 bmp 文件数据创建 MFC CBitmap
- 从存储为 Windows 资源 (c++) 的 png 中获取 png 文件数据
- 如何在 Gnuplot 中分别绘制 2 个文件数据?我有一个文件"sin.txt",另一个文件"cos.txt",我想将它们分别绘制在一个图表上
- 获取文件数据预处理器宏
- 错误的值是使用c++从CSV文件数据写入数组
- 无法在可视C++中检索资源文件数据
- 将文本文件数据读入字符数组时提取运算符的歧义
- 如何使用curl c ++源代码发布wav文件数据,如何使用c ++使用--data-binary?
- 如何在C++中读取 UTF-8 文件数据
- 如何在结构中存储二进制文件数据
- 无法从 turbo c 程序中的文件检索文件数据
- 使用 fstream 将文件数据从当前位置保存到文件末尾
- 通过Google Protobuf发送二进制文件数据
- 在通过套接字向服务器发送文件数据时,我得到了一些垃圾值?为什么
- 如何使用dlang读取二进制文件数据
- 程序使用FSCANF读取文件数据后崩溃
- 检测二进制文件数据的端性
- C++ 从文本文件数据类型读取为结构,并将数据存储在列表的向量中
- 将 FFT 应用于 WAV 文件数据的 C++
- C++内存映射的文件数据预取