使用C ++编程访问C驱动器

时间:2016-05-07 19:19:16

标签: c++

我有一个项目必须将文件隐藏到图像中,首先我使用了命令提示符,并且进展顺利。现在我尝试使用C ++编程语言来应用这些命令,但是每次它给我系统找不到指定的路径,尽管它存在并且使用命令提示符工作得很好。

这是我的代码:

system("cd\\"); \\access C
system("cd x"); \\X is name of folder in C
system("copy /b pic.jpg + file.rar NEWPICTURE.jpg");

这是命令的来源:http://www.instructables.com/id/How-to-Hide-Files-Inside-Pictures/

1 个答案:

答案 0 :(得分:3)

Every time you call system(), a new shell process is created to run that single command. When that shell exits, its local context, including working directory and environment variables, is lost. The next call to system() copies the context of the parent process (your program) all over again.

Your options are to pass a command list/pipeline to a single system() call, or to use functions that affect your own process context, such as chdir().