私は "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で発生しました。
コードが必要な場合は、私に知らせてください!
コードを要求された人もいます。ここでは、次のとおりです。(MacOS Xの10.7.2上)
#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