小编Dav*_*mes的帖子

按myvector排序矢量[i] [0]

我有一个矢量矢量,如下:

vector< vector<int> > intervals;
Run Code Online (Sandbox Code Playgroud)

基本上,我需要使用STL的sort()对矢量进行排序,但我需要为interval [i] [0]排序'interval'.因此,通过每个对象的[0]元素对矢量对象进行排序.

我怎样才能做到这一点?先感谢您.

c++ algorithm

1
推荐指数
1
解决办法
79
查看次数

带opengl的math_3d.h

所以,我正在阅读http://ogldev.atspace.co.uk/www/tutorial02/tutorial02.html,它说我需要math3d.h for Vector3f.

我试图把它包括在内:

#include <stdio.h>

#include "GL/glew.h"
#include "GL/gl.h"
#include "GL/freeglut.h"

#include "math_3d.h"

void render() {
  glClearColor(0.0, 0.0, 0.0, 0.0);
  glClear(GL_COLOR_BUFFER_BIT);
  glutSwapBuffers();

  glFlush();
}

int main(int argc, char** argv) {
  glutInit(&argc, argv);
  glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA);
  glutInitWindowSize(800, 600);
  glutInitWindowPosition(100, 100);
  glutCreateWindow("OpenGL - First window demo");

  /* Set  */
  GLenum res = glewInit();
  if (res != GLEW_OK) {
    fprintf(stderr, "Error: '%s'\n", glewGetErrorString(res));
    return 1;
  }

  Vector3f vertices[1];

  glutDisplayFunc(render);
  glutMainLoop();

  return 0;
}
Run Code Online (Sandbox Code Playgroud)

G ++说"main.cpp:7:21:致命错误:math_3d.h:没有这样的文件或目录".我为它寻找了一个Arch Linux软件包,但我一无所获.

我在这里找到了这个文件:

http://ogldev.googlecode.com/svn-history/r75/trunk/tutorial36/math_3d.h

我应该下载该文件并将其放在我的项目目录中,还是有更简洁的方法呢?

另外,如果我将它包含在我的目录中,我该如何将它添加到g …

c++ opengl g++

1
推荐指数
1
解决办法
4573
查看次数

Lua将文本文件读取到数组中

我怎么能读这样的文件:

11111
10001
10001
10001
11111
Run Code Online (Sandbox Code Playgroud)

对于像这样的二维数组:

{{1, 1, 1, 1, 1},
 {1, 0, 0, 0, 1},
 {1, 0, 0, 0, 1},
 {1, 0, 0, 0, 1},
 {1, 1, 1, 1, 1}}
Run Code Online (Sandbox Code Playgroud)

在Lua?

这就是我的想法:

for i = 1, number_of_lines do
  current_line = map_file:read("*line")
  character_array = {}
  for i = 1, #current_line do
    table.insert(character_array, current_line[i])
  end
end
Run Code Online (Sandbox Code Playgroud)

但是,我不知道如何获得'number_of_lines',这就是带有Lua的文本文件中的行数.我该怎么做?

此外,如果有其他更简单的方法,请告诉我有关它.

lua

1
推荐指数
1
解决办法
2481
查看次数

程序读取太多十进制的情况

我正在尝试阅读3个花车.我尝试用浮动和双打来​​做这个,但我对两者都有相同的行为.

输入示例:

3 1 2
32.0 54.7 -2
Run Code Online (Sandbox Code Playgroud)

第一行有3个整数,第二行有3个浮点数:

我怎么读:

vector<int> order;
vector<double> numbers;
unsigned int order_number;
double number;
char input_character;

while (true)
{
  scanf("%d", &order_number);
  order.push_back(order_number);

  scanf("%c", &input_character);

  if (input_character == ' ')
    continue;
  else
    break;
}

while (true)
{
  scanf("%lf", &number);
  numbers.push_back(number);

  scanf("%c", &input_character);

  if (input_character == ' ')
    continue;
  else
    break;
}

printf("%d %d %d\n", order[0], order[1], order[2]);
printf("%lf %lf %lf\n", numbers[0], numbers[1], numbers[2]);
Run Code Online (Sandbox Code Playgroud)

打印时,我得到:

32.000000 54.700000 -2.000000
Run Code Online (Sandbox Code Playgroud)

我想要32.0,54.7 而且-2.我知道我可以指定要打印的小数位数%.x,但我需要打印输入中给出的数量. …

c++ floating-point stdio

1
推荐指数
1
解决办法
1107
查看次数

使用自定义CSS内容处理列表项内的段落

这是一个段落在非样式列表项(<li>)中的样子:

在此输入图像描述

<li>
  <p>
    hehehe
    hehehe
    hehehe
    hehehe
    hehehe
    hehehe
    hehehe
    hehehe
    hehehe
    hehehe
    hehehe
    hehehe
    hehehe
    hehehe
    hehehe
    hehehe
    hehehe
    hehehe
  </p>
</li>
Run Code Online (Sandbox Code Playgroud)

但是,使用自定义列表样式类型时,它看起来像这样:

在此输入图像描述

这个HTML是:

<li class="docs-test">
  <p>
    hehehe
    hehehe
    hehehe
    hehehe
    hehehe
    hehehe
    hehehe
    hehehe
    hehehe
    hehehe
    hehehe
    hehehe
    hehehe
    hehehe
    hehehe
    hehehe
    hehehe
    hehehe
  </p>
</li>
Run Code Online (Sandbox Code Playgroud)

CSS是:

.docs-test {
  color: red;
  list-style-type: none;
}

.docs-test::before {
  content: '\2022 ';
  color: #828282;
  display: inline-block;
  margin-right: 10px;
}

.docs-test p {
  display: inline-block;
}
Run Code Online (Sandbox Code Playgroud)

我知道对于这个特定的自定义列表样式类型,我可以使用list-style-image.但是,我有其他海关清单样式类型,我不能使用列表样式图像.

我怎样才能使自定义CSS内容列表样式类型的列表项内的段落不跳转到下一行"行"的开头?目标是这些自定义列表样式列表以与没有样式的常规列表相同的方式处理段落.

http://jsbin.com/kimilaniga/1/edit?html,css,output

html css html-lists css-content

1
推荐指数
1
解决办法
868
查看次数

Emacs的最后一行

在此输入图像描述

正如您在该图像中看到的,我可以将光标移动到最后一行(如果我在最后一行的最后一列使用RET),最后一行不会出现在左行号列上.

它也没有突出显示,但只要我输入它,就像我输入"a"一样,它将突出显示并显示在左侧的行号列表中.

这是一个非常小的错误,但它有点让我恼火 - 它确实不是一个主要问题,但我真的想要一种解决方法.

谢谢!

emacs

0
推荐指数
2
解决办法
1102
查看次数

'<< ='运算符做什么以及它叫什么?

  dy <<= 1;
  dx <<= 1;
Run Code Online (Sandbox Code Playgroud)

这是我发现的一些C++代码,它对变量做了什么,以及该运算符调用了什么?

c++

0
推荐指数
1
解决办法
96
查看次数

STL排序不起作用

for (i = 0; i < t; i++)
{
  values.clear();

  scanf("%d %d %d", &values[0], &values[1], &values[2]);
  printf("%d %d %d\n", values[0], values[1], values[2]);
  sort(values.begin(), values.end());
  printf("%d %d %d\n", values[0], values[1], values[2]);

  printf("Case %d: %d\n", i + 1, values[1]);
}
Run Code Online (Sandbox Code Playgroud)

我有那个小片段.我输入"1200 1500 1800"它应该给我中间值 - 1500.但是,它输出1200,最小值.

我所做的是使用STL的sort()来对矢量进行排序,然后打印值[1],这是中间值.

但是,sort()似乎根本不起作用,之前和之后的打印矢量是相同的.

我用以下内容声明我的向量:

vector<int> values (3);
Run Code Online (Sandbox Code Playgroud)

我尝试用它vector<int> values;然后push_back(0)三次声明它.

我想知道为什么它不能以第一种方式工作.

c++ sorting stl

0
推荐指数
2
解决办法
156
查看次数

用于检查干净的 git diff 的 Makefile 目标

我正在尝试编写一个Makefile目标,该目标检查在运行另一个目标后运行的 git 存储库中没有未提交的更改。

这是我到目前为止:

check-git-clean: other-target
ifneq ($(shell git diff-index --quiet HEAD; echo $$?), 0)
    $(error "There are uncomitted changes after running make other-target")
endif
Run Code Online (Sandbox Code Playgroud)

但是,我所经历的是,如果other-target未提交的原因发生变化,ifneq则不会捕获它。另一方面,如果我运行之前已经有未提交的更改make check-git-clean,那么它ifneq会捕获它。

因此,在某种程度上,它几乎就像在ifneq“之前”运行一样,make other-target但是我得到的 CLI 输出(回显)的顺序是正确的。

我想知道我如何才能做到这一点。

git bash makefile

0
推荐指数
1
解决办法
959
查看次数

标签 统计

c++ ×5

algorithm ×1

bash ×1

css ×1

css-content ×1

emacs ×1

floating-point ×1

g++ ×1

git ×1

html ×1

html-lists ×1

lua ×1

makefile ×1

opengl ×1

sorting ×1

stdio ×1

stl ×1