컴파일하지 않을 코드가 있습니다.C++ 바이너리 파일 정렬
#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <string>
#include <Windows.h>
#include <iomanip>
using namespace std;
int average (int n);
int main()
{
string filename;
int i,j;
int n = 0;
int sum = 0;
int size = 4;
const int nameLength = 19;
const int maxRecords = 100;
int index[100];
int scores[maxRecords];
char names[maxRecords][nameLength];
int count = 0;
cout << "Enter binary data directory and file name: ";
getline (cin, filename);
// Open file for binary read-write access.
ifstream fin(filename.c_str(), ios::binary);
if (!fin) {
cout << "Could not open " << filename << endl;
system("PAUSE");
return -1;
}
// Read data from the file.
while (
fin.read(names[count], sizeof(names[0]))
&& fin.read((char *) &scores[count], sizeof(scores[0]))
)
{
count++;
fin.ignore(); // skip the padding byte
}
// Display the data and close.
cout << "Your file's data unsorted: " << endl;
cout << endl;
cout << setw(10) << "Name" << setw(20) << "Test Score" << endl;
for (i=0;i<n;i++){
cout << setw(10) << names[i] << setw(20) << scores[i] << endl;
}
for (i=0;i<n;i++)
{
index[i]=i;
}
for (i=0;i<n;i++)
{
for (j=i+1;j<n;j++)
{
int temp;
if (scores[index[i]] > scores[index[j]])
{
temp = index[i];
index[i] = index[j];
index[j] = temp;
}
}
}
cout << "The average of the test scores in your file is: " << average (sum);
sum=sum+scores[i];
fin.close();
system("PAUSE");
return 0;
}
int average (int sum, int size)
{
return sum/size;
}
나는 말한다 컴파일 오류 받고 있어요 : fatal error LNK1120: 1 unresolved externals
, 그리고 그 이유를 알아낼 수 없습니다. 또한 또 다른 질문은 원래 바이너리 파일에서 읽은 데이터가 훼손되지 않고 출력되고 새로운 편집 된 바이너리 파일에 저장되도록 어떻게 포맷합니까?
int average (int n);
하지만 당신은 이런 식으로 평균 구현 :
정확한 오류 메시지 란 무엇인가요? –
정확하게 ''은 포함되었지만 ''은 포함되지 않는 이유는 무엇입니까? 나는 여기서 전자를 보지 못했지만'system'은 후자의 것입니다.'system ("PAUSE")는 코드가 가져야하는 것이 아닙니다. –
chris
오류 메시지에 "치명적인 오류 LNK1120 : 1 개의 해결되지 않은 외부" "가 있습니다. 이전에을 가지고 있었기 때문에 거기서 MAX_PATH 일을 꺼 냈습니다. –
user2444400