C++ 如何用矢量移动恒星
我想用向量移动星星,我有两个向量,这是我的代码,但当我运行它时,我的开始出错了,我如何解决这个问题 代码:C++ 如何用矢量移动恒星,c++,vector,C++,Vector,我想用向量移动星星,我有两个向量,这是我的代码,但当我运行它时,我的开始出错了,我如何解决这个问题 代码: #包括 #包括 #包括 #包括 #包括 使用名称空间std; void gotoxy(int-eex,int-eey) { 合作社; 坐标X=eex; 坐标Y=eey; 设置控制台或位置(GetStdHandle(标准输出句柄),坐标); } int main() { 向量tmp(2);//对于x,y位置 向量main(0);//用于重新定位x,y的最后位置 int x=2,y=2,l
#包括
#包括
#包括
#包括
#包括
使用名称空间std;
void gotoxy(int-eex,int-eey)
{
合作社;
坐标X=eex;
坐标Y=eey;
设置控制台或位置(GetStdHandle(标准输出句柄),坐标);
}
int main()
{
向量tmp(2);//对于x,y位置
向量main(0);//用于重新定位x,y的最后位置
int x=2,y=2,lx,ly;
对于(int i=2;i您只查看main[0]
,因此推送到向量上的所有其他元素都将被忽略
我看不出将位置推到向量上,然后直接在同一个循环中处理它们的意义。这是一个非常混乱的代码。看,我想连续移动星星,我先在tmp向量中保存每个位置,然后将temp保存到主向量中,然后从主向量重新定位并打印“”但是我的开始出错了。你应该阅读有关调试像这样的小程序的内容。要求internet调试你的程序不是很有效。Stackoverflow到底能帮我们什么忙?:)这是我的问题,我试图解决这个问题,但我做不到,所以我在这里提到了我认识这个代码:)好的,请告诉我们为什么你要把tmp
vector保存到main
vector。为什么?如果你只是想把两颗星星像蛇一样移动,你真的不需要main
vector。顺便问一下,你研究过我给出的两个来源吗“最后一次是你吗?”我的朋友
#include <iostream>
#include <vector>
#include <conio.h>
#include <windows.h>
#include <stdio.h>
using namespace std;
void gotoxy(int eex, int eey)
{
COORD coord;
coord.X = eex;
coord.Y = eey;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
}
int main()
{
vector <int> tmp(2);//for x,y location
vector <vector<int> > main(0);//for relocation of x,y last place
int x=2,y=2,lx,ly;
for(int i=2;i<20;i++){
tmp.at(0)=i;//save the location of x
tmp.at(1)=y;//save the location o y
main.push_back(tmp);//push the x,y into this vector
gotoxy(i,y);//go to location
cout<<"*";
Sleep(100);
lx=main[0][i-1];//relocate the last x
ly=main[0][1];//lelocate the last y
gotoxy(lx,ly);//go to the last location of " *"
cout<<" ";
}
}