"lotto.cpp"라고 불리는 C++에서 약간의 로또 프로그램을 만들었을 때 나는 정말 이상한 것을 보았습니다. 내 프로그램을 위해 파일 쓰기를 쓸 때까지 모든 것이 잘되었다. 우연의 일치소스 파일의 이름이 컴파일에 영향을주는 이유는 무엇입니까?
ld: can't open output file for writing: lotto, errno=21 for architecture x86_64
collect2: ld returned 1 exit status
, 나는이 "하여 1.cpp"내 프로그램의 이름을 변경하고, 갑자기이 문제없이 컴파일 : 내가 컴파일 할 때, 나에게 다음과 같은 오류를 보여 주었다. 또한 이름을 "test.cpp"로 변경했을 때도 효과가있었습니다.
정말 이런 일이 일어난 이유에 대해 궁금합니다. 어떤 아이디어?
이 문제는 MacBook Pro에서 발생했습니다.
코드를 원한다면 알려주세요.
일부 사람들은 코드를 묻습니다. 여기있다 :
이#include <iostream>
#include <fstream>
using namespace std;
const int NED = 10;
const int VIKING = 6;
const int NORMAL = 7;
const int MAX = 10;
void quickSort(int arr[], int left, int right);
int checkDuplicates(int arr[], int length);
int main (int argc, const char *argv[])
{
int i, j, k, ans;
char ans2;
int lottoNumbers[MAX];
ofstream out("Lotto.txt", ios::out | ios::app);
srand((unsigned)time(NULL));
do
{
do
{
cout << "\n\nDo you want to play Viking Lotto (press 6), or normal Lotto (press 7): ";
cin >> ans;
}while(ans != VIKING && ans != normal);
(ans == VIKING) ? cout << "\nViking Lotto:\n" : cout << "\n\nnormal Lotto:\n";
(ans == VIKING) ? out << "\nViking Lotto:\n" : out << "\n\nnormal Lotto:\n";
for (i = 0; i < NED; i++) //10 rows
{
for (j = 0; j < ans; j++) //6 or 7 columns
{
(ans == VIKING) ? lottoNumbers[j] = (rand() % 48) + 1 : lottoNumbers[j] = (rand() % 34) + 1;
}
if(checkDuplicates(lottoNumbers, ans) != -1)
{
for(k = 0; k < ans; k++)
{
while(checkDuplicates(lottoNumbers, ans) == lottoNumbers[k])
{
(ans == VIKING) ? lottoNumbers[k] = (rand() % 48) + 1 : lottoNumbers[k] = (rand() % 34) + 1;
}
}
}
quickSort(lottoNumbers, 0, ans - 1);
cout << '\n';
for(j = 0; j < ans; j++)
{
cout << lottoNumbers[j] << '\t';
out << lottoNumbers[j] << '\t';
}
out << '\n';
}
cout << "\n\n";
cout <<"Another lottery ticket (Y/N) ";
cin >> ans2;
}while(ans2 == 'j' || ans2 == 'J');
cout << "\n\nLOTTO NUMBERS WAS WRITTEN TO FILE...\n\n";
return 0;
}
void quickSort(int arr[], int left, int right)
{
int i = left, j = right;
int tmp;
int mid = arr[(left + right)/2];
while (i <= j)
{
while (arr[i] < mid) i++;
while (arr[j] > mid) j--;
if (i <= j)
{
tmp = arr[i];
arr[i] = arr[j];
arr[j] = tmp;
i++;
j--;
}
};
if (left < j) quickSort(arr, left, j);
if (i < right) quickSort(arr, i, right);
}
int checkDuplicates(int arr[], int length)
{
for(int i = 0; i < length; i++)
{
for(int j = i + 1; j < length; j++)
{
if(arr[i] == arr[j]) return arr[j];
}
}
return -1;
}
코드를 입력하십시오. 권한없이 파일을 편집하는 것 같습니다. – beta0x64
또한 디렉토리 구조 (디렉토리 이름과 파일 이름)를 제공하십시오. – beta0x64
'/ usr/include/sys/errno.h '의 오류 21은'EISDIR'입니다. 디렉토리에 쓰려고 했습니까? – Gaius