In C++, the cout object belongs to
the ostream class. The iostream header file defines it. It's used to send the
output to a standard output device for display. Using the insertion operator (<<),
the data to be displayed on the screen is inserted into the standard output
stream (cout).
Without new line -:
Ex 01:
//Header files
#include <iostream>
//Declare namespace
using namespace std;
//main function
int main() {
//output to the console window
cout << "Hello World!";
cout << "This is iedumax C++ tutorial time.";
//end of the program
return 0;
}
With new line -:
The lines that are supposed to be output in multiple lines occur
in a continuous line. The programmer needs to provide additional data to the
compiler about the new lines. There are two ways to provide the line information
to the compiler.
- Use endl manipulator at the end of the statement.
- Place \n at the beginning, at the middle, or at the end of the output text.
Ex 02:
#include <iostream>
using namespace std;
int main() {
cout << "Hello World!" << endl;
cout << "This is iedumax C++ tutorial time.";
return 0;
}
#include <iostream>
using namespace std;
int main() {
cout << "Hello World! \n\n";
cout << "This is iedumax C++ tutorial time.";
return 0;
}
#include <iostream>
using namespace std;
int main() {
cout << "Hello World!";
cout << "\nThis is iedumax C++ tutorial time.\n\nThank you.";
return 0;
}
Good Job
ردحذفإرسال تعليق