Translate

About Print Multiple Lines and The String in C++


Program listings in this section will print the message (output) and will be shown on multiple lines. In the previous tutorial we use \ n (backslash-n) then the tuorial this time we'll use the command standard C++ where the command that we will use "endl;" (previously the old version taken from the command standard basis of C). example:

#include <iostream>
using namespace std;
int main() {
cout << "I am New To C++," << endl;
cout << "i use the devc++ compiler" << endl;
cout << "because it's the simple one for me" << endl;
system("PAUSE");
return 0;
}

If these characters were omitted, the program would print: I am New To C++,i use the devc++ compiler because it's the simple one for me.

which is not what was wanted.

So, what will the output then? It will print:
I am New To C++,
i use the devc++ compiler
because it's the simple one for me

We can print any number of separate items in a way nenulis all the syntax in a row, and output the results to be displayed will not advance to the next line. We can store multiple items to the console with a single statement: cout << "This is my " << "new " << "C++ program.";
which prints the following when run: This is my new C++ program.

Or you can embed a newline, as this example: cout << "This is my" << endl << "new C++ program.";
which prints the following:
This is my
new C++ program.

And then return a value by using the return statement: return 0;
Which returning a value is the process of sending back a signal to the operating system or development environment, in this case mean the return value of main is a code sent to the operating system, in which 0 indicates success.

I'd like to ask about What is a String?
For the example of the statement: cout << "I am new in C++ language program here!";
In reality, all the data on computers stored in numeric as a value. But depending on how data is used, it can be interpreted as a string of printable characters. That’s the case here.

All of us already know about “ASCII code.” That’s what kind of data “I am new in C++ language program here!” is in this example. The characters l, a, n, g, u, a, g, e, and so on, are stored in individual bytes, in which each is a numeric code corresponding to a printable character.
We’ll discuss a lot more about this kind of data in next tutorial. And now, the important thing to keep in mind is that text enclosed in quotes is considered raw data, as opposed to a command. This kind of data is considered a string of text or, more commonly, just a string.

No comments:

Post a Comment