小编Net*_*peC的帖子

打开gl窗口没有显示?

#include <iostream>
#include <stdio.h>
#include <GL/glut.h>
#include <windows.h>
#include <math.h>

using namespace std;
void display(void) {
    float cx = 200, cy = 200, rad = 50;
    float startx = cx - rad;
    float starty = cy;
    int x = startx, y = starty;

    glColor3f(1.0f, 0.0f, 0.0f);
    glBegin(GL_POINTS);
    glVertex2f((x - 250.f) / 250.f, (250.f - y) / 250.f);

    while (x < cx + rad) {    
        x++;
        y = cy - sqrt(rad * rad - (x - cx) * (x - cx)); …
Run Code Online (Sandbox Code Playgroud)

c c++ opengl graphics

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

OpenCL编译器错误C4996

我是opencl domian的新手.我已阅读了一些书籍并尝试编译以下代码

#define __CL_ENABLE_EXCEPTIONS
#define __NO_STD_VECTOR
#define PROGRAM_FILE "blank.cl"
#define KERNEL_FUNC "blank"
//#define __MAX_DEFAULT_VECTOR_SIZE 100

#include <cstdio>
#include <fstream>
#include <iostream>
#include <iterator>

#ifdef Windows
    #include <OpenCL/cl.hpp>
#else
    #include <CL/cl.hpp>
#endif

using namespace std;
using namespace cl;

int main() {
    // int n = 10;    
    vector<Platform> platforms;
    vector<Device> devices;

    try {
    } catch (exception e) {
    }
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

但它给了我很多错误.

其中大多数如下

Error   14  error C4996: 'cl::vector<char *,10>': was declared deprecated   C:\Program Files (x86)\AMD APP SDK\2.9\include\CL\cl.hpp    1138    1   Matrix_multilpy_C
Run Code Online (Sandbox Code Playgroud)

那么任何人都可以帮助我.我使用visual …

c++ opencl visual-studio-2012

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

unsigned long int给出整数溢出

我试图在c中创建一个程序来解决数独游戏,其中我试图在无符号长整数变量中存储一个等于2*3*5*7*11*13*17*19*23*29的数字.在32位Ubuntu机器上使用boath gcc和g ++进行编译时,我收到整数溢出错误.

请帮我存储和使用这个号码,或建议替代方案.

我将整个代码包括在内以供参考.

#include <stdio.h>
#include <stdlib.h>

int main() {
    int sudoku[9][9] = {2, 8, 0, 0, 0, 3, 0, 0, 0, // 0 is used to denote blank
                        4, 7, 0, 0, 8, 6, 0, 9, 1, 0, 0, 5, 0, 9, 0, 2, 3, 0,
                        0, 9, 0, 5, 2, 0, 4, 8, 6, 5, 0, 0, 0, 0, 0, 0, 0, 3,
                        8, 6, 1, 0, 7, 4, 0, 5, 0, 0, 3, 4, 0, …
Run Code Online (Sandbox Code Playgroud)

c integer-overflow unsigned-long-long-int

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

c编程 - 无法获得所需的输出

char choice, y, n;
float percentage;
int marks;
printf("Do you want to know your percentage?(y/n):\n\n");
scanf(" %c", &choice);
if (choice == 'y') {
    printf("Enter Your 2nd Sem Marks:\n\n");
    scanf(" %d", &marks);
    percentage = (marks / 775) * 100;
    printf("Your 2nd Sem Percentage is %.2f", percentage);
} else
    printf("Thankyou!!!!\n\n\n");
Run Code Online (Sandbox Code Playgroud)

我无法使用上面的代码计算百分比 - 我输出0.00 ...

例如,当我输入为536而不是显示结果为69.16时,它显示0.00请帮助我

c

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

C++ - 找不到运算符

我有一个向量填充自定义类型的值,并且find()算法抱怨它无法为值比较找到合适的==运算符.我已经实现了这样:

bool Ship::operator==(const Ship& source) {
    return (_type == source._type &&
            _damagedSquares == source._damagedSquares &&
            _orientation == source._orientation && _state == source._state);
}
Run Code Online (Sandbox Code Playgroud)

我也尝试了"朋友"方法,但这也不起作用.类本身的结构如下:

class Ship {
private:
    ShipType _type;
    int _damagedSquares;
    ShipOrientation _orientation;
    ShipState _state;

public:
    Ship();
    Ship(ShipType type);
    ~Ship();

    bool operator==(const Ship& source);
};
Run Code Online (Sandbox Code Playgroud)

我在这做错了什么?

附加信息:

std::vector<Ship> remainingShips;
MultiArray& squares = opponentGridCopy.GetSquares();
for (RowIterator rowIterator = squares.begin(); rowIterator != squares.end();
     ++rowIterator) {
    for (ColumnIterator columnIterator = rowIterator->begin();
         columnIterator != rowIterator->end(); ++columnIterator) {
        Square* current = &(*columnIterator);
        SquareState currentState …
Run Code Online (Sandbox Code Playgroud)

c++ vector operator-overloading

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

对于级联成员函数调用,为什么我需要返回引用?为什么不只是这个指针足够了?

#include <iostream>

using namespace std;

class armon {
    int a;
    int b;

public:
    armon(int newA, int newB) : a(newA), b(newB) {}

    armon setA(int newA) {
        a = newA;
        return *this;
    }

    armon setB(int newB) {
        b = newB;
        return *this;
    }

    void print(void) { cout << a << endl << b; }
};

int main() {
    armon s(3, 5);

    s.setA(8).setB(9);

    s.print();
}
Run Code Online (Sandbox Code Playgroud)
  1. 为什么我不能只用这个指针返回对象来进行级联函数调用?
  2. 为什么我需要返回对象的引用?
  3. 甚至会做什么?

c++ reference function cascading this-pointer

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

C++中递归的完整虚拟

嗨,大家好我最近学习了递归,我尝试了很多返回类型,似乎我在过去的一两天里一直在努力解决这个问题.可悲的是,我没有运气.

这个想法是:

  1. 我输入一个值和基数
  2. 找到它的第一个余数并将其存储在一个字符串中.
  3. 然后将值除以基数以获得新值
  4. 重复进程直到值为0或1,然后返回整个字符串.

码:

string convert(int value, int b){
    stringstream s;
    //Once the value is 0 or 1 it returns the whole result
    if(value ==0 || value ==1)
        return s.str();
    else
    {
        //I store the remainder results in the stringstream and call the function again
        s<<convert(value/b,b)<<value%b;
    }
}
Run Code Online (Sandbox Code Playgroud)

c++ recursion

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

如何使用goto跳转到for循环的末尾,但不要离开它

我有一个函数,可以在向量中找到所有多个元素.如果我发送{1,2,3,4,5,1,2,3,3,7}它返回{1,2,3}.我的输入向量有大约100到10000个元素,但我希望只有很少的不同(!)重复; 约1-5%.

因此,如果我已经多次识别出一个元素,我会检查我的重复矢量.如果是,则该函数将继续执行下一个元素(如果有).为此我用了一个goto.

但是我需要在之后有一个命令goto label.否则编译器会抱怨.有没有办法避免这个并保持goto?我知道我可以使用其他方法,例如相应地设置bool并使用if().不过我认为goto方法很简单.

vector<int> findDublicates(vector<int> const& v) {
    // e.g. {1,2,3,4,5,1,2,3,7} -> {1,2,3}
    vector<int> dublicates;
    for (auto it(v.begin()); it != v.end() - 1;
         ++it) { // go through each element except the last
        for (auto const& i :
             dublicates) { // check if this is already a known dublicate
            if (i == *it)
                goto nextElement; // if so, goto the next element in v
        }
        for (auto it2(it + 1); …
Run Code Online (Sandbox Code Playgroud)

c++ goto stdvector

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