이 코드는 매우 매우으로 매우 잘 이해되어 있으며 매우 이해하기가 어려울 수 있지만 내 문제는 언제나 그럼, 약 20 회마다 내가 컴파일 (나는 코드 :: 블록 IDE와 MinGW 컴파일러를 사용한다) 파일은 열리지 않으며 액세스가 거부된다고 말한다. 결코을 빌드 할 수 있습니다. 빌드 & 코드 실행/실행 :: 블록 프로그램은 notes.txt라는 텍스트 파일을 열어 쓰기를 허용합니다. , 읽거나 삭제할 수 있습니다.txt에 무작위로 열거 나 쓰는 기본 프로그램이 닫히거나 열리지 않는다
편집 내가 바로 실행에서 파일을 부팅 할 때, 나는 오류 메시지가이 오류는 온라인 수정이 "libgcc_s_dw2-1.dll 컴퓨터에서 누락"얻을주의하는 것도 중요하다 여기에는 내 컴파일러의 bin 폴더에있는 모든 .dll을 내 실행 파일의 루트로 옮기는 작업이 포함됩니다. 이 수정 프로그램은 프로그램을 시작할 때 작동하지만 프로그램이 즉시 중단됩니다. 이것은 내가 컴파일러 구성 오류가 될 수 있다고 생각합니다. 약간의 설명은 크게 감사 할 것입니다.
이 문제는 컴파일러 문제입니까? 메모리 누출인가요? 실제로 프로그램의 결함인지 확실하지 않지만 (이것은 끔찍하고 끔찍하고 지저분한 코드에 대해 다시 사과합니다) 전체 프로그램입니다.
int main(){
char a;
char c;
int b = 0;
int ans = 0;
int err = 0;
int isopen = 0;
int deleteerror = 0;
int god = 0;
string info;
string docinsert;
string writeto;
fstream notes;
notes.open("notes.txt");
cout << "What would you like to do to the text in this document?"<<endl<<"Over[W]rite, [R]ead, [D]elete." << endl;
cin >> a;
while (b != 1){
if (err != 0){
cout << "Please retry." << endl;
cin >> a;
}
switch(a){
case 'W':
case 'w':
b = 1;
ans = 1;
break;
case 'R':
case 'r':
b = 1;
ans = 2;
break;
case 'D':
case 'd':
b = 1;
ans = 4;
break;
default:
err = 1;
cout << "An error has occurred." << endl;
}
}
if (notes.is_open()){
isopen = 1;
switch (ans){
case 1:
cout << "Please write what you wish to put within the document.\nThis will DIRECTLY overwrite anything previously written.\nIn order to avoid unwanted characters, delete before overwriting." << endl << endl;
cin.clear();
cin.sync();
getline(cin, docinsert);
cout << endl;
notes << docinsert;
break;
case 2:
cout << endl << "This is what is currently written within the document:" << endl;
getline(notes, info);
cout << info << endl;
break;
case 4:
cout << endl << "This is what is currently written within the document:" << endl;
getline(notes, info);
cout << info << endl;
cout << endl << "Please confirm you wish to delete all information in this document.\n[D]elete, [C]ancel.\n\n";
cin >> c;
while (god != 2){
if (god = 1){
cout << "Please repeat input to verify.\n";
cin >> c;
}
if (c == 'D' || c == 'd'){
notes.close();
ofstream notes("notes.txt");
cout << "File wiped." << endl;
return 0;
}
else if(c == 'C' || c == 'c'){
cout << "\nNo information removed.";
return 0;
}
else{
cout << "An error has occured.\n";
god = 1;
}
}
default:
cout << "An error has occurred.\n";
return 0;
}
}
else if(isopen != 1){
cout << endl << "An error with reading the file has occurred.\nIf this error persists, create a text document\nnamed 'notes' in the root directory of this program.\n";
}
}
''notes.txt ''와 같은 파일 이름을 사용할 때 파일은 현재 디렉토리에서 무엇이든 열리게됩니다. 어떤 장소에서는 파일을 만들거나 권한이 없을 수도 있습니다. 파일에 대한 전체 경로를 사용하면 파일이 끝나는 위치를 정확하게 알 수 있습니다. –
"파일이 열리지 않고 액세스가 거부되었다고 말하면"notes.txt가 이겼음을 의미합니까? 프로그램이 실행되지 않거나 액세스가 거부 된 메시지는 무엇입니까? –
이 문제는 실행 파일을 실행하는 데 문제가 있으므로 "notes.txt"와 관련이없는 것으로 보입니다. 이 특정 도구 모음을 사용하여 동일한 문제가 발생했습니다 (googled). – user2672165