내가 엉망인 것을 알아낼 수 없습니다. 나는 값이 어지럽고 이것을 고치려고 노력하고 있다고 생각합니다. 이 코드는 간단한 배열로 생각되지만이 파일을 정렬하려고하는데이 오류가 발생합니다.구조체 배열을 알파벳순으로 정렬
1>ClCompile:
1> Main.cpp
1>Main.obj : error LNK2019: unresolved external symbol "void __cdecl sort(struct salesTran * const,int)" ([email protected]@[email protected]@[email protected]) referenced in function _main
1>C:\Users\BranN3W\Documents\Visual Studio 2010\Projects\3-1Notes\Debug\3-1Notes.exe : fatal error LNK1120: 1 unresolved externals
1>
1>Build FAILED.
1>
1>Time Elapsed 00:00:01.96
========== 빌드 : 0, 0 ==========
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
struct salesTran {
string name;
double quantity,price;
};
void swap(salesTran A[], int i, int j);
void sort(salesTran A[], int size);
ostream& operator << (ostream& os, salesTran A)
{os << A.name << "\t" << A.quantity << "\t" << A.price;
return os;}
istream& operator >> (istream& is, salesTran& A)
{is >> A.name >> A.quantity >> A.price;
return is;}
int main()
{
salesTran data[250];
ifstream fin;
fin.open("sales.txt");
ofstream fout;
fout.open("results.txt");
int index = 0;
fin >> data[index];
while(!fin.eof())
{
index++;
fin >> data[index];
}
sort(data, index);
for(int j=0; j < index; j++)
{
cout << data[j] << endl;
}
return 0;
}
void swap(int data[], int i, int j)
{
int temp;
temp = data[i];
data[i] = data[j];
data[j] = temp;
return;
}
void sort(int data[], int size)
{
for(int p=1; p<size; p++)
{
for(int c=0; c<size-p; c++)
{
if(data[c]>data[c+1]) swap(data,c,c+1);
}
}
return;
}
누구나 나를 올바른 방향으로 안내 할 수 있습니까? 나는 정말로 도움을 사용할 수있다. 나는 이것을 알아 내고 나를 죽이고 싶다. 나는 맹세하고 모든 책을 검사했지만, 나는이 책을 읽을 수는 없다. – user2133925
아마도 ** prototype으로 선언하는 것보다는 * void 정렬 (salesTran A [], int size);를 ** 정의하는 것이 도움이 될 것입니다. 리스트의 맨 아래에있는 sort() 루틴은'void sort (int data [], int size)'입니다. 매개 변수 목록을보십시오. – WhozCraig
[정의되지 않은 참조/확인되지 않은 외부 기호 오류 란 무엇이며 어떻게 수정해야합니까? : 선언 된 변수와 정의되지 않은 변수 또는 함수.] (http://stackoverflow.com/a/12574403/902497) –