小编Ben*_*igt的帖子

glReadPixels返回错误的值

我尝试渲染像素颜色.

gl.glColor3f(1f, 0, 0);
//draw
gl.glReadPixels(lastX - pw / 2, MyCanvas.this.getHeight()
            - (lastY - ph / 2), pw, ph, GL.GL_RED, GL.GL_FLOAT,
            pixelBuffer);
float r, g, b;
r = pixelBuffer.getFloat();
g = pixelBuffer.getFloat();
b =pixelBuffer.getFloat();
pixelBuffer.rewind();
System.out.println(r+" "+g+" "+b);
Run Code Online (Sandbox Code Playgroud)

屏幕上有真正的纯红色,但glReadPixels返回到非常奇怪的值4.6006E-41,为什么???

java opengl jogl endianness glreadpixels

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

为什么有SIGFPE?

由于某种原因,它曾经工作过.但现在我得到了一个SIGFPE .....出了什么问题?

#include "usefunc.h"

long factorial(long num) {
    if (num > 1) {
        long counter;
        long fact = 1;
        for (counter = num; counter > 0; counter--) fact *= counter;
        return fact;
    }
    else return 0;
}

long combinations(long n, long k) {
    return (factorial(n)) / (factorial(k)*factorial(n-k));
}

int main()
{
    printf("How many rows of Pascal\'s triangle should I print?\t");
    int rows = GetInteger();
    long pArray[rows][rows];
    int counter;
    int counter2;
    for (counter = 1; counter <= rows; counter++)
    {
        int …
Run Code Online (Sandbox Code Playgroud)

c signals sigfpe pascals-triangle

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

为什么 ::CreateProcess(path,cmd,...) 失败并显示错误“找不到文件”?

我正在尝试让 C++ 程序调用一个已经制作的 C# 程序在后台运行。

STARTUPINFO info = {sizeof(info)};
PROCESS_INFORMATION processinfo;
DWORD error1 = GetLastError();
bool x = ::CreateProcess((LPCWSTR)"C:\Convert_Shrink.exe", GetCommandLine(), NULL, NULL, false, 0,NULL,NULL, &info, &processinfo);
DWORD error = GetLastError();
Run Code Online (Sandbox Code Playgroud)

在 CreateProcess 之前 error1 为 0,在 CreateProcess 之后 error 为 2

错误2:

ERROR_FILE_NOT_FOUND 2 (0x2) The system cannot find the file specified.
Run Code Online (Sandbox Code Playgroud)

我已将其更改为 C:\ \ incase 他们正在检查转义序列,但我仍然收到错误 2,我不知道为什么。

c++ winapi

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

C++中的声明符

什么是C++中的init-declarator和声明符之间的区别?init-declarator可能出现在init-declarator-list中.例:

int x, y, z;
Run Code Online (Sandbox Code Playgroud)

要么

  int x;
  int y;
  int z;
Run Code Online (Sandbox Code Playgroud)

其中x,y,z可能是init-declarators或我应该说声明者?

c++ declaration language-lawyer

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

可以使用CreateFile对没有管理员权限的物理驱动器进行读取访问吗?

我试图使用CreateFile从MBR中读取一些数据,但是如果没有管理员权限我无法使用它.

我使用的代码是这样的:

hDevice = CreateFile("\\.\PhysicalDrive0", GENERIC_READ, FILE_SHARE_READ Or FILE_SHARE_WRITE, 0, OPEN_EXISTING, 0, 0)
Run Code Online (Sandbox Code Playgroud)

是否可以在没有管理员权限的情况下从MBR读取数据?

vb.net winapi

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

为什么当它应该像try/catch/finally一样使用时抛出异常?

据我所知,使用像try/catch/finally这样的工作,所以我希望如果在using语句中发生异常它会被捕获(这有点奇怪,因为这也意味着异常被默默地吃掉了).using语句应该捕获异常并调用Dispose方法,但是,没有发生.我已经设计了一个简单的测试来证明这个问题.

这是我强制在using语句中发生异常的地方:

using (TcpClient client = new TcpClient())
{
    // Why does this throw when the using statement is supposed to be a try/catch/finally?
    client.Connect(null);
}
Run Code Online (Sandbox Code Playgroud)

抛出异常client.Connect()(意味着它没有被using语句捕获或者被重新抛出):

System.ArgumentNullException: Value cannot be null.
Parameter name: remoteEP
   at System.Net.Sockets.TcpClient.Connect(IPEndPoint remoteEP)
   at DotNETSandbox.Program.Main(String[] args) in C:\path\to\Sandbox\Program.cs:line 42
Run Code Online (Sandbox Code Playgroud)

根据微软关于该主题的文章,如果Dispose方法抛出,则可能会抛出using语句.

但是,当我遵循使用模式时,显然Dispose方法不会抛出:

TcpClient c2 = new TcpClient();
try
{
    c2.Connect(null);               
}
catch (Exception e)
{
    // We caught the null ref exception
    try
    {
        // Try to dispose: …
Run Code Online (Sandbox Code Playgroud)

c# exception using-statement try-catch

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

从int**到const int的转换无效**

我有一个类,其中一个二维数组的int实现为int**.我按如下方式为这个2D数组实现了一个访问器函数,返回一个const int**以防止用户编辑它:

const int** Class::Access() const
{
     return pp_array;
}
Run Code Online (Sandbox Code Playgroud)

但是我得到了编译错误"从int**到const int**的无效转换".为什么不允许在这里推广const?如何在不编辑权限的情况下授予用户访问信息的权限?

c++ const multiple-indirection implicit-conversion

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

C++ 11"自动"到非C++ 11编译器

我从中下载了源代码

http://matt.eifelle.com/2012/07/17/just-a-small-example-of-numerical-optimization-in-c/

并尝试在g ++ 4.4.6中编译,它不知道以下来源的auto:

  auto optimizer = Optimization::Local::build_simplex( 
  fun,
  Optimization::Local::make_and_criteria(Optimization::Local::IterationCriterion(max_iterations),
      Optimization::Local::RelativeValueCriterion<float>(ftol))); 
Run Code Online (Sandbox Code Playgroud)

阅读网页,我知道这是因为C++ 11支持auto,所以我尝试搜索我下载的内容,有一个simplex.h,它有以下源代码:

template<class Function, class Criterion>
static Simplex<typename Function::DataType, typename Function::ParameterType, Function, Criterion> build_simplex(const Function& fun, const Criterion& criterion)
{
  return Simplex<typename Function::DataType, typename Function::ParameterType, Function, Criterion>(criterion);
}
Run Code Online (Sandbox Code Playgroud)

然后我改变了

auto optimizer  
Run Code Online (Sandbox Code Playgroud)

Simplex<typename Function::DataType, typename Function::ParameterType, Function, Criterion> optimizer
Run Code Online (Sandbox Code Playgroud)

或者

Optimization::Simplex<typename Function::DataType, typename Function::ParameterType, Function, Criterion> optimizer
Run Code Online (Sandbox Code Playgroud)

没有人会通过编译器!!

我不太了解c ++的模板用法,除了得到一个c ++ 11编译,我应该为这个自动做什么返回数据类型修改?

更新:

感谢好心帮我修改要int optimizer和编译,我得到了: test_rosenbrock_simplex.cpp:44: error: cannot convert Optimization::Local::Simplex<float, Eigen::Matrix<float, 2, 1, 0, 2, 1>, …

c++ g++ c++11

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

将2-D数组传递给函数会产生奇怪的错误

嗨,我正在尝试创建一个函数,但它给出了错误

  [Error] cannot convert 'float (*)[(((sizetype)(((ssizetype)n) + -1)) + 1)]' to 'float (*)[30]' for argument '1' to 'float vecino_mas_cercano(float (*)[30])'
Run Code Online (Sandbox Code Playgroud)

我的代码是:

#include <iostream>
#include<stdio.h>
#include <fstream>
#include<stdlib.h>
using namespace std;

int n1=30;

float nearest_neighbor(float distances[30][30])
{  float min=distances[0][1];
   int candidates[n1];
   int city=0;

   for (int i=0;i<n1;i++)
   {  candidates[i]=i;
   }

   for (int i=0;i<n1;i++)
   {  for (int &j:candidates)
      {  if (j!=0)
            if (distances[city][j]<min);
            {  min=distances[i][j];
               candidates[i]=0;
               city=j;
            }
      }
   }
   return min;
}

int main()
{
   //Declaración de variables

   int n=30; //número de …
Run Code Online (Sandbox Code Playgroud)

c++ arrays pointers function

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

Char和int16数组元素都显示为32位十六进制?

在下面的示例中:

int main(int argc, char *argv[])
{
    int16_t array1[] = {0xffff,0xffff,0xffff,0xffff};
    char array2[] = {0xff,0xff,0xff,0xff};
    printf("Char size: %d \nint16_t size: %d \n", sizeof(char), sizeof(int16_t));

    if (*array1 == *array2)
        printf("They are the same \n");
    if (array1[0] == array2[0])
        printf("They are the same \n");

    printf("%x \n", array1[0]);
    printf("%x \n", *array1);

    printf("%x \n", array2[0]);
    printf("%x \n", *array2);
}
Run Code Online (Sandbox Code Playgroud)

输出:

Char size: 1 
int16_t size: 2 
They are the same 
They are the same 
ffffffff 
ffffffff 
ffffffff 
ffffffff
Run Code Online (Sandbox Code Playgroud)

32位值为什么印刷两种charint16_t,为什么他们能进行比较和被认为是一样的吗?

c variadic-functions integer-promotion

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