haoningabc 发表于 2013-2-5 02:13:20

c++的helloworld

helloworld
#include <iostream>using namespace std ;int main (){      int a , b;      cout << " Pleaseinput two numbers :";      cin >> a >> b;      cout << a << "+" << b << "=" << a + b << endl ;      return 0;}
--------------------------------------------
直接输入和输出到文件
#include <iostream>#include <fstream>using namespace std;ifstream fin ("sum.in");ofstream fout ("sum.out ");int main (){      int a , b;      fin >> a >> b;      fout << a + b << endl ;      return 0;}
---------------------------------
#include <stdio.h>union {      int a ;      double b;      char c ;} x;int main (){      x.c = 'G';      x.c = 'O';      x.c = 'O';      x.c = 'D';      x.c = 'B';      x.c = 'A';      x.c = 'B';      x.c = 'Y';      printf ("int : %dbyte (s)\n" , sizeof (int ));      printf (" double : %dbyte (s)\n" , sizeof ( double ));      printf (" char : %dbyte (s)\n" , sizeof ( char )); //       printf (" bool : %dbytes (s)\n" , sizeof ( bool ));      printf ("\n");      printf (" integer : %d %d\n" , x.a , x.a );      printf (" real   number : %e\n" , x.b);      printf (" characters : %c%c%c%c%c%c%c%c\n" , x.c , x.c , x.c ,                        x.c , x.c , x.c , x.c , x.c );      printf ("HEX : %X%X%X%X%X%X%X%X\n" , x.c , x.c , x.c , x.c ,                        x.c , x.c , x.c , x.c );      return 0;}~
页: [1]
查看完整版本: c++的helloworld