又有了一个第一次,linux下的C程序: 1 //file HelloWorld.cpp 2 #include <stdio.h> 3 int main(int argc, char **argv) 4 { 5 printf("hello linux world\n"); 6 } 编译命令:g++ -o helloworld helloworld.cpp 运行命令:./helloworld 结果:hello linux world 自己要注意的问题: 1 是<stdio.h> 还有另外一种写法: 1 //file HelloWorld.cpp 2 #include <stdio.h> 3 #include <iostream.h> 4 5 int main() 6 { 7 // printf("hello linux world\n"); 8 cout<<"hello world linux\n"<<endl; 9 //cout.operator<<("Hello,World!").operator<<(endl); 10 return 0; 11 } 1 注意cout的输出语句为:cout<<"hello world linux\n"<<endl;不知道网上为何有的人把后面的<<endl去掉。没有放全么? 2 在按照网上原码编译时出现了如下问题:`cout' undeclared (first use this function)。在网上查知道没有引入#include <iostream.h> 3 第9行相当于是理解cout的运行原理,放在下面:cout是一个iostream类的对象,它有一个成员运算符函数operator<<,每次调用的时候就会向输出设备(一般就是屏幕啦)输出东东。出处:http://tech.163.com/05/1123/11/2388N2D40009159Q.html

评论