Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/132.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
第二行文本文件未读取;C++;;Visual Studio 我在第二年的计算机科学课上,我们正在学习C++。_C++_Visual Studio_File_Text_Getfiles - Fatal编程技术网

第二行文本文件未读取;C++;;Visual Studio 我在第二年的计算机科学课上,我们正在学习C++。

第二行文本文件未读取;C++;;Visual Studio 我在第二年的计算机科学课上,我们正在学习C++。,c++,visual-studio,file,text,getfiles,C++,Visual Studio,File,Text,Getfiles,作业是编写一个文本文件,并根据文本文件的数据计算总数和平均数 这是我的文本文件的外观: Angela Langston Maya Malcolm Total Average Algebra 64.5 56.7 67.4 90.0 CS1 88.6 77.0 55.3 89.4 English 91.3 67.4 89.0 100.0 Science 100.0 89.4 80.2 91.4 Average 在编译和调

作业是编写一个文本文件,并根据文本文件的数据计算总数和平均数

这是我的文本文件的外观:

        Angela Langston Maya Malcolm Total Average
Algebra  64.5   56.7    67.4  90.0
CS1      88.6   77.0    55.3  89.4
English  91.3   67.4    89.0  100.0
Science  100.0  89.4    80.2  91.4
Average
在编译和调试之前,我一直做得很好。我的程序无法正确打印文本文件的第二行。它打印出:

-107374176.0-107374176.0-107374176.0-107374176.0-429496704.0-107374176.0

而不是我存储在文本文件中的数据

请帮忙。我将提供解决此问题所需的任何其他信息。另外,提醒一下,我是初学者C++用户。 更新: 代码如下:

#include <iostream>
#include <string>
#include <iomanip>
#include <fstream>
using namespace std;

void student_heading();
void report_heading();
float average_calc(float);

int main()
{
cout << fixed << showpoint << setprecision(1);

string name1, name2, name3, name4;
string title1, title2;
string class1, class2, class3, class4, title3;
string fecha;
float algebra1, cs1, english1, science1;
float algebra2, cs2, english2, science2;
float algebra3, cs3, english3, science3;
float algebra4, cs4, english4, science4;
float algebra_total;
algebra_total = 0;
float cs_total = 0;
cs_total = 0;
float english_total = 0;
english_total = 0;
float science_total;
science_total = 0;
float algebra_avg, cs_avg, english_avg, science_avg;
float angela_avg, langston_avg, maya_avg, malcolm_avg;
float angela_total, langston_total, maya_total, malcolm_total;
angela_total = algebra1 + cs1 + english1 + science1;
langston_total = algebra2 + cs2 + english2 + science2;
maya_total = algebra3 + cs3 + english3 + science3;
malcolm_total = algebra4 + cs4 + english4 + science4;
angela_avg = average_calc(angela_total);
langston_avg = average_calc(langston_total);
maya_avg = average_calc(maya_total);
malcolm_avg = average_calc(malcolm_total);
student_heading();

cout << "What is today's date? (Example: May 1, 1996 = 05/01/1996): " << endl;
cin >> fecha;
cout << "DATE:" << fecha << "*************************************************** Page 1" << endl;
report_heading();

ifstream inData;
inData.open("infile.txt");
inData >> name1 >> name2 >> name3 >> name4 >> title1 >> title2;
cout << "         " << name1 << "  " << name2 << "  " << name3 << "  " << name4 << "  " << title1 << "  " << title2 << endl;

inData >> class1 >> algebra1 >> algebra2 >> algebra3 >> algebra4 >> algebra_total >> algebra_avg;
algebra_total = algebra1 + algebra2 + algebra3 + algebra4;
algebra_avg = average_calc(algebra_total);
cout << class1 << "   " << algebra1 << "    " << algebra2 << "     " << algebra3 << "    " << algebra4 << "   " << algebra_total << "    " << algebra_avg << endl;

inData >> class2 >> cs1 >> cs2 >> cs3 >> cs4 >> cs_total >> cs_avg;
cs_total = cs1 + cs2 + cs3 + cs4;
cs_avg = average_calc(cs_total);
cout << class2 << "       " << cs1 << "    " << cs2 << "     " << cs3 << "    " << cs4 << "   " << cs_total << "    " << cs_avg << endl;

inData >> class3 >> english1 >> english2 >> english3 >> english4 >> english_total >> english_avg;
english_total = english1 + english2 + english3 + english4;
english_avg = average_calc(english_total);
cout << class3 << english1 << english2 << english3 << english4 << english_total << english_avg;

inData >> class4 >> science1 >> science2 >> science3 >> science4 >> science_total >> science_avg;
science_total = science1 + science2 + science3 + science4;
science_avg = average_calc(science_total);
cout << class4 << science1 << science2 << science3 << science4 << science_total << science_avg;

inData >> title3;
cout << title3 << angela_avg << langston_avg << maya_avg << malcolm_avg << endl;

inData.close();
return 0;

}

void report_heading()
{
cout << "********************SMALL COLLEGE GRADE REPORT*******************"   << endl;
}

void student_heading()
{
cout << "*******************" << endl;
cout << "Student" << endl;
cout << "ID" << endl;
cout << "SYCS-135 Computer Science I" << endl;
cout << "Assignment 5" << endl;
cout << "September 24, 2015" << endl;
cout << "******************" << endl;
}

float average_calc(float total_value)
{
float average;
average = total_value / 4;
return average;
#包括
#包括
#包括
#包括
使用名称空间std;
无效学生_标题();
无效报告标题();
浮动平均值(浮动);
int main()
{
标题1>>标题2;
cout>代数平均值;
代数总数=代数1+代数2+代数3+代数4;
代数平均值=平均值(代数总数);
cout cs_avg;
cs_总计=cs1+cs2+cs3+cs4;
cs_平均值=平均计算值(cs_总计);
美国英语协会;
英语总量=英语1+英语2+英语3+英语4;
english_avg=平均计算值(英语总数);
科学3>>科学4>>科学总量>>科学平均值;
科学总数=科学1+科学2+科学3+科学4;
科学平均=平均计算(科学总计);
不能这条线

inData >> class1 >> algebra1 >> algebra2 >> algebra3 >> algebra4 >> algebra_total >> algebra_avg;
尝试将字符串“CS1”读入
代数\u total
,这会导致流失败。请不要尝试读取这些数字,或者将文本文件修复为类似的格式

        Angela Langston Maya Malcolm Total Average
Algebra  64.5   56.7    67.4  90.0   0    0
CS1      88.6   77.0    55.3  89.4   0    0
English  91.3   67.4    89.0  100.0  0    0
Science  100.0  89.4    80.2  91.4   0    0
Average

在您显示代码之前,很难说出明确的内容。@Atomic#u alarm我已经添加了代码。嘿,我完成了代码,现在它给了我一个调试错误。有任何注释吗?运行时检查失败#3-T@Quishe'分支必须有比错误中更多的信息。'Assignment 5.exe'(Win32):加载的“C:\Windows\SysWOW64\cryptbase.dll”。找不到或打开PDB文件。“分配5.exe”(Win32):加载的“C:\Windows\SysWOW64\bcryptprimitives.dll”。找不到或打开PDB文件。“分配5.exe”(Win32):加载了“C:\Windows\SysWOW64\kernel.appcore.dll”。找不到或无法打开PDB文件。线程0x1438已退出,代码为0(0x0)。线程0x28c4已退出,代码为0(0x0)。线程0x3be8已退出,代码为0(0x0)。程序“[12712]赋值5.exe”已退出,代码为0(0x0)@user657267您确定使用的代码与问题中的代码完全相同吗?在“运行时检查失败”3之后是否没有其他代码?