귀하의 질문이 완전한 답변을 얻는데 충분한 정보를 제공하지 않습니다. 언어로서의 C++은 실제로 그 의미에서 폴더 나 파일을 다루는 함수를 가지고 있지 않습니다. 왜냐하면 C++은 플랫폼에 독립적이어서 Windows, MacOS, iOS, Android, Linux에서 파일 시스템조차 갖고 있지 않은 다른 많은 장치에서 실행되도록 C++ 코드를 컴파일 할 수 있기 때문입니다.
물론 귀하의 경우에는 Windows 또는 Linux를 언급하고있을 것입니다. 그렇다면 어떤 파일인지에 따라 파일 시스템 기능을 사용하여 파일 시스템의 파일을 복사하거나 이동할 수 있습니다.
Windows의 경우 Win32 API에는 파일을 복사하는 데 CopyFile 및 CopyFileEx 함수가 있고 파일을 이동하거나 이름을 바꾸려면 MoveFile 및 MoveFileEx 함수가 있습니다.
Linux의 경우 sendfile API 함수를 사용하여 커널을 사용하여 파일을 복사 할 수 있습니다.
오픈/읽기/쓰기 기능을 사용하여 파일의 내용을 다른 파일로 복사하려면 C/C++에서 플랫폼 독립적 인 코드를 작성할 수 있습니다 (즉, 소스 파일을 읽기 모드로 열고, 소스 파일의 끝에 도달 할 때까지 쓰기 모드에서 대상 파일을 연 다음 소스에서 읽기 및 목표에 기록)하지만 플랫폼 별 라이브러리가 없으면 다른 파일 시스템 기능을 재생하는 것이 더 어렵지는 않습니다.
int inputFileDesc;
int outputFileDesc;
struct stat statBuffer;
off_t offset = 0;
// open the source file, and get a file descriptor to identify it later (for closing and sendfile fn)
inputFileDesc = open ("path_to_source_file", O_RDONLY);
// this function will fill the statBuffer struct with info about the file, including the size in bytes
fstat (inputFileDesc, &statBuffer);
// open the destination file and get a descriptor to identify it later (for closing and writing to it)
outputFileDesc = open ("path_to_destination_file", O_WRONLY | O_CREAT, statBuffer.st_mode);
// this is the API function that actually copies file data from source to dest;
// it takes as params the descriptors of the input and output files and an offset and length for the amount of data to copy over
sendfile (outputFileDesc, inputFileDesc, &offset, statBuffer.st_size);
close (outputFileDesc); // closes the output file (identified by descriptor)
close (inputFileDesc); // closes the input file (identified by descriptor)
http://advancedlinuxprogramming.com/과 같은 Linux 또는 Posix 프로그래밍에 대한 유용한 책을 읽었습니까? –
가능할 수도 있지만, 당신이하고 싶은 것이 무엇인지는 명확하지 않습니다. – Matt