Skip to main content

  | मौसम…

411 समाचार
Public archive edition · Attributed source reporting with original dates · AI drafts are excluded

411 REFERENCE · Wikibooks

Modern C++: The Good Parts/The world's response

Reference material by Wikibooks contributors. This retains its source identity and is not 411 news reporting.

Now, let's allow the world to return the greeting. Code #include <iostream> #include <string> int main() { std::string input; std::cout << "Hello, world!\n"; // Notice the arrows point to the right. std::cin >> input; std::cout << "The world says: " << input << "\n"; } Explanation We have a few new things here. std::string means that input is a string variable. A variable is a named place in memory to store information. Since it's named, you can refer to it again and again, to put something there or to see what's already there. And as a string variable it can store text - and only text. Other kinds of variables exist, and we'll cover some of those in the next chapter. // is a line comment, which means everything after it on the same line will be ignored by the compiler. std::cin has an arrow that points in the opposite direction from the arrows of std::cout, because information is flowing in the opposite direction. After "The world says: ", there's another arrow, and then another. This just appends more text to the output. Exercises Extend the conversation between your program and the "world". Don't bother with whether the program is responding correctly to what is typed. Vocabulary variable a named place in memory to store information. line comment causes the compiler to ignore the rest of a line. Syntax: // Anatomy of a global greeting Number crunching