在C++中,`cout`是标准输出流对象,用于在控制台打印信息。以下是一些使用`cout`的示例程序:
基本输出
```cpp
include using namespace std; int main() { cout << "Hello, World!" << endl; return 0; } ``` ```cpp include using namespace std; int main() { int num = 100; cout << "The value of num is: " << num << endl; return 0; } ``` ```cpp include include using namespace std; int main() { float pi = 3.14159265358979323846; cout << "The value of pi is: " << fixed << setprecision(5) << pi << endl; return 0; } ``` ```cpp include include using namespace std; int main() { string name = "Alice"; cout << "Hello, " << name << "!" << endl; return 0; } ``` ```cpp include include using namespace std; int main() { int age = 25; cout << "I am " << setw(3) << setfill('0') << age << " years old." << endl; return 0; } ``` ```cpp include using namespace std; int main() { for (int i = 1; i <= 9; i++) { for (int j = 1; j <= i; j++) { cout<< j << " * "<< i << " = " << i * j << "\t"; } cout << endl; } return 0; } ``` 这些示例展示了如何使用`cout`进行基本的输出操作,包括输出字符串、整数、浮点数,以及如何使用格式化输出。建议在实际编程中根据需求选择合适的输出方式和格式。输出整数
输出浮点数
输出字符串
输出格式化
输出矩阵