c++语言代码爱心跳动
时间: 2023-11-16 13:00:15 浏览: 108
会跳动的爱心代码,下载用浏览器打开就行
以下是一个使用C++语言编写的爱心跳动代码,它使用了Windows API中的Sleep函数和gotoxy函数来实现爱心的跳动效果:
```cpp
#include <iostream>
#include <windows.h>
using namespace std;
void gotoxy(int x, int y) {
COORD pos = { x, y };
HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorPosition(hOut, pos);
}
int main() {
int x = 40, y = 12;
while (true) {
gotoxy(x, y);
cout << " ** **" << endl;
gotoxy(x, y + 1);
cout << "********" << endl;
gotoxy(x, y + 2);
cout << "********" << endl;
gotoxy(x, y + 3);
cout << " ****** " << endl;
gotoxy(x, y + 4);
cout << " ***** " << endl;
gotoxy(x, y + 5);
cout << " *** " << endl;
Sleep(500);
system("cls");
gotoxy(x, y);
cout << " ** **" << endl;
gotoxy(x, y + 1);
cout << "**** ****" << endl;
gotoxy(x, y + 2);
cout << "**********" << endl;
gotoxy(x, y + 3);
cout << "**********" << endl;
gotoxy(x, y + 4);
cout << " **** ****" << endl;
gotoxy(x, y + 5);
cout << " ** **" << endl;
Sleep(500);
system("cls");
}
return 0;
}
```
阅读全文