1.修改Hello.cpp,使它能打印你的名字和年龄(或你的鞋码,爱犬的年龄等,只要你喜欢)。编译并运行修改后的程序
修改前的Hello.cpp
#include <iostream>
using namespace std;
int main()
{
cout<<"Hello, World! I am "<< 8 <<" Today!"<<endl;
}
输出结果为:
[root@localhost tttt]# g++ hello.cpp -o hello
[root@localhost tttt]# ./hello
Hello, World! I am 8 Today!
>
修改后的Hello.cpp如下:
#include <iostream>
using namespace std;
int main()
{
cout<<"Hello, World! I am "<< 8 <<" Today!"<<endl;
cout<<"My name is "<<"C++"<<" , and i am "<<21<<" years old!"<<endl;
}
输出结果如下:
[root@localhost tttt]# ./hello
Hello, World! I am 8 Today!
My name is C++ , and i am 21 years old!
>
原程序如下:
#include <iostream>
using namespace std;
int main()
{
int r;
cout<<"请输入半径的大小 r = ";
cin>>r;
double s = 3.14 *r * r;
cout<<"圆的面积为 S = "<<s<<endl;
}
执行结果为:
[root@localhost tttt]# ./hello
请输入半径的大小 r = 4
圆的面积为 S = 50.24
原程序如下:
#include <string>
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
ifstream