我正在尝试使用 SDL 渲染一个点,但似乎无法获取要渲染的点。我在代码中没有收到任何错误,并且正在编译,但是窗口上没有出现任何内容。
代码:
#include <iostream>
#include <SDL2/SDL.h>
using namespace std;
int main() {
const int windowHeight = 600;
const int windowWidth = 800;
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
return 1;
cout << "Initialization failed" << endl;
}
SDL_Window *window = SDL_CreateWindow("Practice making sdl Window",
SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, windowWidth,
windowHeight, SDL_WINDOW_SHOWN);
if (window == NULL) {
SDL_Quit();
return 2;
}
SDL_Renderer *s;
const int pointLocationx = windowWidth/2;
const int pointLocationy = windowHeight/2;
SDL_RenderDrawPoint(s, pointLocationx, pointLocationy);
bool quit = false;
SDL_Event event; …Run Code Online (Sandbox Code Playgroud) 我开始学习更多关于矢量的知识.我被告知要做的第一个练习练习之一是使用'迭代器格式'输出数组的内容.作为一个额外的练习,我被告知尝试使用与指针算法类似的相同方法反向打印数组.
#include <iostream>
#include <vector>
using namespace std;
int main(){
vector<int> arr;
arr.push_back(1);
arr.push_back(2);
arr.push_back(3);
arr.push_back(4);
for(vector<int>::iterator it = arr.end(); it >= arr.begin(); it--){
cout << *it << endl;
}
}
Run Code Online (Sandbox Code Playgroud)
输出如下:
-820575969
4
3
2
1
Run Code Online (Sandbox Code Playgroud)
该程序正在运行,它以相反的顺序打印出数组中的数字.然而,为什么第一件事输出了一些长的负数?谢谢你的帮助.
约翰