linux的c++编译示例

c.cc文件:

#include <iostream>
#include <stdlib.h> 
#include <stdio.h>

int main(int argc, char const *argv[])
{
	int a,b,c;
	a = atoi(argv[1]); //字符串转整数
	b = atoi(argv[2]);
	c = a * b;
	char *outcome;
	sprintf(outcome,"%d",c); //整数转字符串
	std::cout<<argv[1]<<"*"<<argv[2]<<"="<<outcome<<std::endl;
	while(getchar()!='q');
	return 0;
}

 

编译:

g++ c.cc -o c

 

运行:

./c Two\ Young

 

结果:

Hello World! Two Young!

 

posted @ 2013-04-30 18:11  catmelo  阅读(245)  评论(0编辑  收藏  举报