用cpp循环输出3次Hallow world
时间: 2024-05-09 14:19:38 浏览: 4
以下是cpp代码,循环输出3次Hallow world:
```cpp
#include <iostream>
int main()
{
for(int i=0; i<3; i++)
{
std::cout << "Hello world" << std::endl;
}
return 0;
}
```
输出结果为:
```
Hello world
Hello world
Hello world
```
相关问题
WPF写一个50s后输出一个窗口“hallow word”,用事件触发的方法
可以使用`DispatcherTimer`类来实现50s后输出一个窗口“Hello World”的效果,代码如下:
```csharp
using System.Windows.Threading;
...
public partial class MainWindow : Window
{
private DispatcherTimer timer;
public MainWindow()
{
InitializeComponent();
timer = new DispatcherTimer();
timer.Tick += Timer_Tick;
timer.Interval = TimeSpan.FromSeconds(50);
timer.Start();
}
private void Timer_Tick(object sender, EventArgs e)
{
MessageBox.Show("Hello World");
timer.Stop();
}
}
```
在窗口加载时,我们创建一个`DispatcherTimer`对象,并设置`Tick`事件,以及定时器的间隔为50秒,然后启动定时器。在`Tick`事件中,弹出一个消息框显示“Hello World”,并停止定时器。这样就可以实现50s后输出一个窗口“Hello World”的效果了。