파일이 존재하는지 여부를 모른다면 그 파일의 내용에 따라 뭔가를 할 것입니다. 파일은 .txt 또는 .gz 형식 일 수 있으며 파일도 존재할 수 없습니다. 내가 예를 들어 hello.abc에 대한 있어야합니다 파일하지만 난 hello.abc 또는 hello.gz 수 검사 할 파일과 같은 이름을 가진 파일을 검사 할zip 파일 또는 압축 파일이 있는지 확인하는 방법은 무엇입니까?
//Check whether is a zip file
char *pre_pcom_file_copy = new char[strlen(pre_pat_file)+7];
strcpy (pre_pcom_file_copy,pre_pcom_file);
strcat (pre_pcom_file_copy,".gz");
char *cmd = new char[strlen("gzip -dc ")+strlen(pre_pcom_file_copy)+1];
strcpy (cmd,"gzip -dc ");
strcat (cmd,pre_pcom_file_copy);
if ((pre_pcom = popen(cmd,"r")) == NULL){
//Do nothing
}else{
cout << "Parsing pre.pcomments file --->" << pre_pcom_file << endl;
pcomyyin = pre_pcom;
if(_vecTime.size() > 0){
//for pre_pcom _vecTime should be empty
pcom_time = _vecTime[_vecTime.size()-1];
}
first_time = 1; // make sure tester cycle start from 0 from pcomment file
pcomyyparse();
pclose(pre_pcom);
//delete [] cmd;
cout << "Parsing pre.pcomments file DONE!" << endl;
}
: 다음은 내 코드입니다 또는 심지어 exist.If 내가 위의 방법으로 파일 hello.txt 또는 hello.gz 완전히 존재하지 않는 오류가있어. 어떻게 내가 이것을 해결할 수 있습니까?
이것은 C++입니다. 'C'란 태그가 붙은 이유는 무엇입니까? –
@JonathonReinhart 왜냐하면 나는 C++과 C를 사용하므로 양쪽에 태그를 붙였습니다. 아니면 C++ 만 넣어야합니까? –
그들은 [다른 언어] (http://programmers.stackexchange.com/questions/38942/how-is-c-different-from-c)입니다. 만약 당신이''cout << ...'을 사용하고 있다면 C가 아닌 C++을 쓰고있는 것입니다. –