Introduction
We use cout to show messages or results on the screen. It helps us communicate what the program is doing.
We use cout to show messages or results on the screen. It helps us communicate what the program is doing.
#include <iostream> int main() { std::cout << "Your message here" << std::endl; return 0; }
std::cout is used to send output to the screen.
<< is called the insertion operator and it sends data to std::cout.
#include <iostream> int main() { std::cout << "Hello, world!" << std::endl; return 0; }
#include <iostream> int main() { int age = 25; std::cout << "Age: " << age << std::endl; return 0; }
<< operators.#include <iostream> int main() { std::cout << "Line 1" << std::endl << "Line 2" << std::endl; return 0; }
This program prints a welcome message and then shows a number.
#include <iostream> int main() { std::cout << "Welcome to the program!" << std::endl; int number = 10; std::cout << "The number is: " << number << std::endl; return 0; }
Always include #include <iostream> to use cout.
std::endl moves the cursor to the next line after printing.
You can print many things in one line by chaining <<.
cout is used to print messages on the screen.
Use << to send data to cout.
End lines with std::endl to start a new line.
std::cout << "Hello, world!" << std::endl;std::cout is used to print output to the screen.std::cout and then adds a new line with std::endl.cout is <<, not >>.std::endl, not end.#include <iostream>
int main() {
std::cout << "Sum: " << 5 + 3 << std::endl;
return 0;
}5 + 3 is evaluated first because + has higher precedence than <<.#include <iostream>
int main() {
std::cout << "Hello" << std::endl
return 0;
}std::endl is missing it.int a = 5; and int b = 10; as "5 10" using cout?<< to send each item separately, including a string with a space.a, then a space string, then b, then ends the line.Pass the test and this pattern moves unknown