Welcome!

Join our community of MMO enthusiasts and game developers! By registering, you'll gain access to discussions on the latest developments in MMO server files and collaborate with like-minded individuals. Join us today and unlock the potential of MMO server development!

Join Today!

C++ 2011 Tutorial 2

Status
Not open for further replies.
Newbie Spellweaver
Joined
Jan 13, 2011
Messages
9
Reaction score
1
Code:
/// Read the program and determine what the program does.

#include <iostream>
#include <istream>
#include <limits>
#include <ostream>

int main()
{
    int min(std::numeric_limits<int>::max());
    int max(std::numeric_limits<int>::min());
    bool any(false);
    int x;
    while (std::cin >> x)
    {
        any = true;
        if (x < min)
            min = x;
        if (x > max)
            max = x;
    }

    if (any)
        std::cout << "min = " << min << "\nmax = " << max << '\n';
}

Hello in this tutorial you will be learning....

Reading C++ Code
What does listing 2-1 do?
______________________________________________
______________________________________________
______________________________________________

Listing 2-1 reads integers from the standard input and keeps track of the largest and smallest values entered. After exhausting the input, it then prints those values. If the input contains no numbers, the program prints nothing.
Lets take a closer look at the various parts of the program.

Comments
Line 1 begins with three consecutive slashes to start a comment. The comment ends at the end of the line. Actually, you need only two slashes to signal the start of a comment (//), but as you will learn later in the book, three has a special meaning. For now though, use three. Note that you cannot put a space between the slashes. That's true in general for all the multicharacter symbols in C++. It's an important rule, and one you must internalize early. A corollary of the "no spaces in a symbol" rule is that when c++ sees adjacent characters, it always tries to construct the longest possible symbol, even if you can see that doing so would produce meaningless results. I predict that this rule will surprise you several Explorations down the road. The other method you can use to write a comment in C++ is to begin the comment with /* and end it with */. The Difference between this style and the style demonstrated in Listing 2-1 is with this method, your comment can span multiple lines. You may notice that some pro-grams in this book use /** to start a comment. Much like the third slash in Listing 2-1, this second asterisk (*) is magic, but unimportant at this time. A comment cannot nest within a comment of the same style, but you can nest one style of comment in comments of the other style, as illustrated in Listing 2-2.

Code:
/** Listing 2-2. Demonstrating Comment Styles and Nesting */
/* Start of a comment /* start of comment characters are not special in a comment
 // still in a comment
 Still in a comment
*/
no_longer_in_a_comment();
// Start of a comment /* start of comment characters are not special in a comment
no_longer_in_a_comment();

if you made the change correctly, the program should still compile and run normally. The compiler eliminates comments entirely, so nothing about the final program should be different. (With one exception being that some binary formats include a timestamps, which would necessarily differ from one compliant ion run to another.

Thats it for tutorial 2.
 
Newbie Spellweaver
Joined
Oct 1, 2008
Messages
10
Reaction score
3
Congratz CodeXI you learned to copy and paste ^^
 
Newbie Spellweaver
Joined
Oct 1, 2008
Messages
10
Reaction score
3
So you made the book called ?

Nope iam not wrong and the link work ^^
 
Status
Not open for further replies.
Back
Top