再编写程序的过程中,使用printf 输出变量值没用,然后用cout进行替换也是没用
#include <stdio.h>
#include <stdlib.h>
#include <iostrea>
#include <string.h>
using namespace std;
int main (int args,char *argv[])
{
if (args !=2) printf("please set prot , such as you can set 8000" );
printf("port : %s",argv[1]);
cout <<port :<<argv[1];
.....
return 0;
}
编译调试后发现 什么都没有输出出来。
查询资料得知 :printf的内容放在缓冲区里面还没有刷出来,原则上是缓冲区满了以后才输出,成为标准输出流,不过你可以在printf后面加一个fflush(stdout);这样就能立即输出来了,或者加上 \n ;
printf("please set prot , such as you can set 8000 \n" );
printf("port : %s \n",argv[1]);
cout <<port :<<argv[1]<<endl;
这样就都输出了