Not saving in a file
I have no idea where is my problem, if you see any other problem with the program please let me know, Thanks!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146
|
#include <iostream>
#include <fstream>
#include<iomanip>
#include <cstdlib>
#include <string>
using namespace std;
class Kursist
{
//private
string ime;
string familia;
int listovka;
int drive1;
int drive2;
public:
Kursist(string name, string lname, int test, int driving1, int driving2)
{
ime=name;
familia=lname;
listovka=test;
drive1=driving1;
drive2=driving2;
}
Kursist() {}
~Kursist() {}
string GetName()
{
return ime;
}
string GetLname()
{
return familia ;
}
int GetTest()
{
return listovka;
}
int GetDriving1()
{
return drive1;
}
int GetDriving2()
{
return drive2;
}
};
void outputLine( Kursist );
int main( )
{
int i;
Kursist kursist[3];
string name;
string lname;
int test;
int driving1;
int driving2;
cout << "Enter the name, family and results.\n";
for (i=0; i<3; i++)
{
cout <<"Ime: \n";
cin >> name;
cout <<"Family: \n";
cin >> lname;
cout <<"Test: \n";
cin >> test;
cout <<"Driving1: \n";
cin >> driving1;
cout <<"Driving2: \n";
cin >> driving2;
Kursist akursist(name, lname, test, driving1, driving2);
kursist[i]=akursist;
}
ofstream outKursistFile;
outKursistFile.open( "kursist18.dat" );
{
if ( !outKursistFile )
cerr << "File could not be opened" << endl;
exit( 1 );
}
for (i=0; i<3; i++)
{
outKursistFile << kursist[i].GetName() << ' ' << kursist[i].GetLname()<< ' '<<kursist[i].GetTest()<< ' ' << kursist[i].GetDriving1() << ' ' <<kursist[i].GetTest()<< '\n';
}
outKursistFile.close();
return 0;
}
void outputLine( Kursist kursist )
{
cout << setiosflags( ios::left ) << setw( 10 ) << kursist.GetName() << setw( 13 ) << kursist.GetLname() <<setw( 7 ) << setprecision( 2 )<< resetiosflags( ios::left )<<kursist.GetTest()<< ' ' <<kursist.GetDriving1()<< ' ' <<kursist.GetDriving2()<< '\n';
}
|
Line 120 always happens, so the program always exits at line 120
Thanks man!
Topic archived. No new replies allowed.