您的位置:首页 > 编程语言 > C语言/C++

如何在CMD下编译连接.CPP文件

2013-06-29 10:43 435 查看
如何在CMD下编译连接.CPP文件  

/////////////////////////////////////////////mycopy.cpp存放在D盘下D:\mycopy.cpp(或是其它路径).

////////程序启动时的"命令行参数"与调用main()的"函数实参"不同.

////////命令行参数是由启动程序截获并找包成字符串数组后传递给main()的一个形参argValue的.

///////而包括命令字(即可执行文件名称)在内的所有参数的个数则被传递给形参argCount.

//mycopy.cpp

#include<stdio.h>

#include<iostream.h>

int main(int argCount, char* argValue[])

{

        FILE *srcFile = 0,*destFile=0;

        int ch = 0;

        if(argCount != 3)

       {

              cout<<argValue[0]<<endl;

              printf("Usage:%s src-file-name dest-file-name\n", argValue[0]);

        }

        else

       {

              if( (srcFile = fopen(argValue[1], "r")) == 0)

             {

                      printf("can not open source file\"%s\" !",argValue[1]);

              }

              else

             {

                      if((destFile = fopen(argValue[2], "w")) == 0)

                      {

                               printf("can not open destination file\"%s\"!",argValue[2]);

                               fclose(srcFile);

                       }

                       else

                       {

                              while((ch = fgetc(srcFile)) != EOF )

                                      fputc(ch, destFile);

                               printf("successful to copy a file!\n");

                               fclose(srcFile);

                               fclose(destFile);

                               return 0;

                        }

              }

       }

        return 1;

}

/////////////////////////////////////////////

 

然后DOS下切换到mycopy.cpp存放的盘符下,现我存放在D盘下

c:\Documents and Settings\Administrator>d:

D:\>CL mycopy.cpp               注释:编译mycopy.cpp , 产生mycopy.obj中间代码文件

D:\>LINK mycopy.obj                注释:连接mycopy.obj文件,生成mycopy.ext文件

D:\>mycopy d:\file2.txt   d:\myfile1.txt              注释:把file2.txt中的内容制到file1.txt文件中去
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: