C++ Primer 读书笔记 - 第一章

这一章算是简介。

自己写了几个程序。

1. main函数的返回值

int main()
{
    //after ./a.out, execute 'echo $?', it will output 7.
    return 7;
}

2. 对comment的理解

#include <iostream>
using namespace std;

int main()
{
    cout << "/*";
    cout << "*/";
    cout << /* "*/" */";
}

3. 对输入的理解

#include <iostream>
using namespace std;

int main()
{
    int a;
    int b;
    cin >> a >> b;
    cout << a << "\t" << b << endl;
    return 0;
}

4. 无限输入

#include <iostream>
using namespace std;

int main()
{
    int sum = 0;
    int value;
    // Ctrl + D to end the input
    while (cin >> value)
        sum += value;
    cout << "Sum is: " << sum << endl;
    return 0;
}

 

posted on 2013-05-19 08:02  NULL00  阅读(737)  评论(3编辑  收藏  举报

导航