C++ Primer(5th)第一章习题答案

来源:互联网 发布:zeroclipboard.js下载 编辑:程序博客网 时间:2024/05/19 17:06

1_3答案

#include <iostream>using namespace std;int main(int argc, char *argv[]){    cout << "Hello World!" << endl;    return 0;}

1_4答案

#include <iostream>using namespace std;int main(int argc, char *argv[]){    cout << "Enter two number: " << endl;    int v1 = 0, v2 = 0;    cin >> v1 >> v2;    cout << "v1 * v2 = " << v1 * v2 << endl;    return 0;}

1_5答案

#include <iostream>using namespace std;int main(int argc, char *argv[]){    cout << "Enter two number: ";    cout << endl;    int v1 = 0, v2 = 0;    cin >> v1 >> v2;    cout << "The sum of ";    cout << v1 << " and " << v2 << " is ";    cout << v1 + v2 << endl;    return 0;}

1_6答案

std::cout << "The sum of " << v1;              << " and " << v2;  //不合法,在<<左侧缺少ostream                                 //输出流,添加std::cout则正确              << " is " << v1 + v2 << std::endl; //不合法,同理

1_8答案

cout << "/*";  //合法cout << "*/";  //合法cout << /* "*/"*/;  //不合法cout << /* "*/" /*"/*" */;  //合法

不合法的修改为

3条语句修改为 cout << /* "*/"*/"; //结果为 */4条语句  cout << /* "*/  <em>" /*"<em> /*" */; //结果为 /*
0 0