Code:I have done like this.. but still many error..
i have change ti float..then for array.total i change to size.total=0.
rror C2228: left of '.push_back' must have class/struct/union type
F:\460.cpp(37) : error C2228: left of '.clear' must have class/struct/union type
F:\460.cpp(40) : error C2228: left of '.push_back' must have class/struct/union type
F:\460.cpp(53) : error C2228: left of '.size' must have class/struct/union type
F:\460.cpp(56) : error C2228: left of '.total' must have class/struct/union type
F:\460.cpp(57) : error C2228: left of '.at' must have class/struct/union type
Error executing cl.exe.
Help with Code Tags C++ Syntax (Toggle Plain Text)
#include <iostream> // std::cout#include <fstream>#include <iomanip>#include <string> // std::string#include <vector> // std::vector<>#include <algorithm> //std::for each()using namespace std; // import "std" namespace into global namespace struct exam{int examid;float total;}; int main() { ifstream stream1("STA83SOLUTION.txt"); if ( !stream1.is_open()) { cout << "While opening a file an error is encountered" << endl; } else { cout << "Fail Di buka....." << endl; } vector <exam> exams; exam aExam; int tempExamID; int tempTotal; stream1 >> tempExamID >> tempTotal; aExam.examid = tempExamID; aExam.total.push_back(tempTotal); // add this exam code to current student's vector of exam codes while (stream1 >> tempExamID >> tempTotal) { if(tempExamID != aExam.examid) { exams.push_back(aExam); // no more exam codes for this student. Add aStudent to students vector aExam.total.clear(); aExam.examid = tempExamID; } aExam.total.push_back(tempTotal); // add this exam code to current student's vector of exam codes } exams.push_back(aExam); // no more exam codes for this student. Add aStudent to students vector stream1.close(); // We have read the entire file, so time to close it.{ ofstream myfile; myfile.open("411.txt"); int temp, flag; if (myfile.is_open()) { for (size_t i = 0; i < exams.size(); i++) { for (size_t j = 0; j<exams.at(i).total.size(); j++) { size.total = 0; cout<<"\n"<<i+1<<":"<<" "<< exams.at (i).total.at(j)<<"\t"; // output list of exam codes for this student } } } cin.get();return 0;}}#include <iostream> // std::cout
#include <fstream>
#include <iomanip>
#include <string> // std::string
#include <vector> // std::vector<>
#include <algorithm> //std::for each()
using namespace std; // import "std" namespace into global namespace
struct exam
{
int examid;
float total;
};
int main()
{
ifstream stream1("STA83SOLUTION.txt");
if ( !stream1.is_open())
{
cout << "While opening a file an error is encountered" << endl;
}
else
{
cout << "Fail Di buka....." << endl;
}
vector <exam> exams;
exam aExam;
int tempExamID;
int tempTotal;
stream1 >> tempExamID >> tempTotal;
aExam.examid = tempExamID;
aExam.total.push_back(tempTotal); // add this exam code to current student's vector of exam codes
while (stream1 >> tempExamID >> tempTotal)
{
if(tempExamID != aExam.examid)
{
exams.push_back(aExam); // no more exam codes for this student. Add aStudent to students vector
aExam.total.clear();
aExam.examid = tempExamID;
}
aExam.total.push_back(tempTotal); // add this exam code to current student's vector of exam codes
}
exams.push_back(aExam); // no more exam codes for this student. Add aStudent to students vector
stream1.close(); // We have read the entire file, so time to close it.
{
ofstream myfile;
myfile.open("411.txt");
int temp, flag;
if (myfile.is_open())
{
for (size_t i = 0; i < exams.size(); i++)
{
for (size_t j = 0; j<exams.at(i).total.size(); j++)
{
size.total = 0;
cout<<"\n"<<i+1<<":"<<" "<< exams.at (i).total.at(j)<<"\t"; // output list of exam codes for this student
}
}
}
cin.get();
return 0;
}
}

