I am writing a program that grabs information from a .dat file. I have the code all structured up, but I get these 2 errors that does not make any sense to me on how to fix the program. Am I missing something?
errors (2):
Code:
Error 1 error LNK2019: unresolved external symbol "void __cdecl swap(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > *,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > *)" (?swap@@YAXPAV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@0@Z) referenced in function "void __cdecl sort(int)" (?sort@@YAXH@Z) C:\Users\Mom\Desktop\Drive\Quarter 2\C++\Projects\DynamicDeptPayroll\DynamicDeptPayroll\Source.obj DynamicDeptPayroll
______________________________________________________________________________
Error 2 error LNK1120: 1 unresolved externals C:\Users\Mom\Desktop\Drive\Quarter 2\C++\Projects\DynamicDeptPayroll\Debug\DynamicDeptPayroll.exe DynamicDeptPayroll
.dat file contents:
Code:
Fogarty Bob 1 40 10.25
Smith John 2 38 8.72
Jones Mary 2 28 6.25
Arrmen William 1 15 8.22
Lavey Betty 1 32 15.00
source contents:
Code:
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
//PROTOTYPES
void sort(int n);
void swap(string *p1, string *p2);
//GLOBAL VARIABLES
string *dept, *name, *grosspay;
int main(){
string d, n, gp;
int count = 0;
double dept1, gpay, totalgpay = 0;
string name1;
//DECLARE FILE OBJECT
ifstream fin("c:\\data\\dept.dat");
while (!fin.eof()){
fin >> d >> n >> gp;
count++;
}
fin.close();
//SIZE ARRAYS
dept = new string[count];
name = new string[count];
grosspay = new string[count];
//LOAD ARRAYS
fin.open("c:\\data\\dept.dat");
for (int i = 0; i < count; i++){
fin >> dept[i] >> name[i] >> grosspay[i];
}
fin.close();
//SORT CALL
sort(count);
for (int i = 0; i < count; i++){
gpay = atof(grosspay[i].c_str());
name1 = atof(name[i].c_str());
totalgpay = gpay / 3;
cout << dept[i] << "\t" << name[i] << "\t" << grosspay[i] << "\n";
cout << "TOTAL GROSS: " << totalgpay;
}
delete[] dept;
delete[] name;
delete[] grosspay;
system("pause");
return 0;
}
void sort(int n){
int i, j, low;
for (i = 0; i < n - 1; i++){
low = i;
for (j = i + 1; j < n; j++)
if (dept[j] < dept[low])
low = j;
if (i != low){
swap(&dept[i], &dept[low]);
swap(&name[i], &name[low]);
swap(&grosspay[i], &grosspay[low]);
}
}
}