小编Jam*_*ley的帖子

用于打印HTML的不同页面方向

码:

我尝试使以下简单的HTML页面工作:

<html>
  <head>
    <style type="text/css">     
    @media print
    {               
      @page port { size: portrait; }
      .portrait { page: port; }

      @page land { size: landscape; }
      .landscape { page: land; }                

      .break { page-break-before: always; }
    }
    </style>
  </head>
  <body>
    <div class="landscape">
      <p>This is a landscape page.</p>
    </div>
    <div class="portrait break">
      <p>This is a portrait page.</p>
    </div>
  </body>
</html>
Run Code Online (Sandbox Code Playgroud)

题:

我想将第一个div的内容打印到第一页,横向打印,第二个打印带纵向打印.但是,所有浏览器(Chrome,Opera,Safari,IE10)都会打印两个纵向页面.我错过了什么或者没有一个浏览器支持这种功能吗?在后一种情况下,是否有任何替代方案可以实现这一结果?

html css3

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

在C++中拥有Big Float

我想在C++中编写自己的变量"type"作为作业.它应该是一个任意长的浮点数.我在想结构......

码:

class bigFloat
{
public:
    bigFloat(arguments);
    ~bigFloat();

private:
    std::vector<char> before; // numbers before decimal point
    std::vector<char> after; // numbers after decimal point
    int pos; // position of decimal point
};
Run Code Online (Sandbox Code Playgroud)

如果我的数字如下:3.1415之前='3'; 之后='1415'; pos = 1; 如果这对你有意义......但是分配要我保存一些内存,我不这样做,因为我分配的每一个数字大约是1个字节,这是我猜的太多了.

题:

你会如何代表那些任意长的数字?(抱歉我的英文不好,希望这篇文章有道理)

c++

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

错误C2061在visual studio中

我尝试在我的代码中引用另一个类的结构,它给了我一个错误,说我有语法问题.

#pragma once

#include "Definitions.h"

#include "GV.h"
#include "UI.h"
#include "Tile.h"
#include "Item.h"

class Figure {
public:
    //Figure index
    struct FIGURE_TYPE {
        //Where to crop the image from
        SDL_Rect crop;
        int x;
        int y;
    };

    //The game figure
    FIGURE_TYPE figure_index[FIGURE_COUNT];

    //The figure array
    int figure_array[MAP_HEIGHT / 64][MAP_WIDTH / 64];

    //Functions
    Figure ( void );
    bool draw_figures ( SDL_Surface* screen, SDL_Surface* figures, SDL_Rect camera, Figure::FIGURE_TYPE figure_spec[FIGURE_COUNT] );
};
Run Code Online (Sandbox Code Playgroud)

那是图.h中的结构,

#pragma once

#include "Definitions.h"

#include "GV.h"
#include "Tile.h"
#include "Item.h"
#include "Figure.h" …
Run Code Online (Sandbox Code Playgroud)

c++

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

SFML 2.0中的重复重复

如果刚刚在SFML中按下(未保持)某个键,或者是模仿这种效果的方法,有没有办法接收?

我在这里调查我的活动,

while (window.pollEvent(event));
Run Code Online (Sandbox Code Playgroud)

然后在循环中,超出范围,但同样的事件,我读到:

if (event.type == sf::Event::KeyPressed)
{
    if (event.key.code == sf::Keyboard::Up)
    {
        decision--;
        if (decision < 0)
        decision = CHARACTER_MAX - 1;
    }
}
Run Code Online (Sandbox Code Playgroud)

decision当按下向上箭头时,这会连续递减.使用sf::events,我可以在第一次按下时读取,而不是在按下时读取吗?

另外,如果它不可能或你不熟悉sfml,那么用很少或没有全局变量来模仿这样的最好的方法是什么?(例如is_already_held),例如https://gamedev.stackexchange.com/questions/30826/action-button-only-true-once-per-press

我意识到这可能是唯一的方法(在更广泛的范围内声明变量)但我不愿意,因为我不断地退出范围并尽可能经常地避开全局变量.

c++ keyboard events sfml

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

如何使用逻辑AND运算符(&&)c ++调用这两个函数

假设我有两个函数和一个变量,

int number;

bool foo (void);
bool footoo (void);
Run Code Online (Sandbox Code Playgroud)

在每个函数中,number都会发生一些带变量的逻辑,例如:

number++;
return(rand()%2);
Run Code Online (Sandbox Code Playgroud)

然后我称他们为:

if (foo() && footoo())
{
    cout << "Two foo true!"
}
Run Code Online (Sandbox Code Playgroud)

为什么不调用这两个函数number?无论返回值如何,我如何保证调用和递增函数?

c++ logical-operators logical-and

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

错误C2512:'Tile':没有合适的默认构造函数可用

即使使用默认构造函数仍然有错误.

class Foo {
    public:
    Foo ( int x, int y, int type );
}
Run Code Online (Sandbox Code Playgroud)

并在.cpp文件中

Foo::Foo ( int x = 0, int y = 0, int type = 0 ) {
Run Code Online (Sandbox Code Playgroud)

然而,当我打电话给它

Foo foo_array[5][5];
Run Code Online (Sandbox Code Playgroud)

我收到了错误.这可能是什么原因?

c++ default-constructor

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

默认值C++ 11,编译器到编译器

问题1:

你怎么知道变量的默认值?那是(如果我的词汇是错误的)变量的值在分配之前?

问题2:

编译器之间有何不同?

问题3:

是否有更好的默认值方法?

问题4:

最后,这条规则还有其他例外吗?

示例代码:

bool foolean;
int fintoo;
double fooble;
char charafoo;
Run Code Online (Sandbox Code Playgroud)

这些是默认编译器到编译器会是什么?

c++ default-value c++11

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

虽然循环混乱

题:

我的while循环没有退出.在调试期间,它非常明确地说stateID等于3.但是,当我添加时,无论调试器告诉我什么,总是std::cout << stateID;将值1写入控制台.

在代码中,我在输入循环渲染屏幕.这表明毫无疑问,输入循环正如预期的那样正确退出.此外,如果这还不够,则必须退出以使stateID首先更改.请不要再讨论嵌套循环了.而且我在循环之后也使用了断点,这些断点被正确击中.

码:

int main()
{

    stateID = 1;

    GameState* state = new GameStateTitle();

    sf::RenderWindow window(sf::VideoMode(1000, 600), "RPG");

    //GAME LOOP//
    while (stateID != 3)
    {//INPUT//
    sf::Event event;
    while (window.pollEvent(event))
    {
        switch (event.type)
        {
        //Window closed
        case sf::Event::Closed:
            set_next_state(3);
            break;
        }
    }

        change_state(state);

    //RENDERING//
    window.clear(sf::Color::Black);

    state->render(window);

    window.display();
    }
    /////////////

    window.close();

    return 0;
}

void set_next_state(int new_state)
{
    //Set the next state to take place
    next_state = new_state;
}

void change_state(GameState …
Run Code Online (Sandbox Code Playgroud)

c++ while-loop sfml

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

如何退出`for`循环的单圈?

在像这样的循环中,

for (int i = 0; i < 5; i++)
{
    int i_foo;

    i_foo = foo();
    if (i < 5)
        return; //<-------- Right here

    footwo();
}
Run Code Online (Sandbox Code Playgroud)

如何返回循环的特定转弯?

我知道我可以在条件下执行footwo()i >= 5,但我想知道是否有办法让循环退出(只有一次).

为了更多的解释,我希望for循环在开始时重新开始并添加1 i,就像它刚刚完成循环的特定"循环"一样.

(根据奇怪的措辞,我无法找到答案,但是如果有一个只是直接指导我,我会高兴地把它取下来.)

c++ for-loop

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

If/Else语句或公式?

问题:

在处理布尔值时,使用if语句或方程通常会更好吗?请解决以下问题,请记住,您的答案应适用于大多数(如果不是全部)代码:

  1. 哪个更快,为什么?或者差异是否太小而不显着?
  2. 其中一个更有活力吗?在某些情况下,他们中的一个可能会与另一个相遇吗?
  3. 哪个是更好/首选的代码,还是完全基于意见的做法?

(我指的是C++,但由于这个问题是半通用的,因此也可以参考或与其他语言进行比较.)

示例(在C++中):

鉴于以下广泛的情况,

int n = (anything);
bool x_not_y = (declared as random boolean value);
Run Code Online (Sandbox Code Playgroud)

目标是使int x = nif x_not_y成立,int y = n而恰恰相反,使用if/else语句更好:

if (x_not_y)
    x = 5;
else
    y = 5;
Run Code Online (Sandbox Code Playgroud)

(以下简称)

x_not_y?x = 5:y = 5;
Run Code Online (Sandbox Code Playgroud)

或者使用方程式

x = (x * (int)!x_not_y) + (5 * (int)x_not_y);
y = (y * (int)x_not_y) + (5 * (int)!x_not_y);
Run Code Online (Sandbox Code Playgroud)

c++ performance equation if-statement

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

列表只能使用Enumeration访问

什么是最好的方法System.Collections.Generic.List,只有一个enum?为了帮助描述我正在寻找的东西,我现在就这样做:

enum MyEnum
{
    First,
    Second,
    Count
}

class MyClass
{
    List<SomeClass> myList = new List<SomeClass>((int)MyEnum.Count);

    MyClass()
    {
        myList[(int)MyEnum.First] = new SomeClass(1);
        myList[(int)MyEnum.Second] = new SomeClass(2);
    }
}
Run Code Online (Sandbox Code Playgroud)

我觉得我错过了什么.有没有更好的方法呢?如果答案很明显,我很抱歉,我发现很难找到听起来如此通用的东西.


作为一些背景,我将使用此列表来访问我的代码中的不同纹理,例如,enum将具有纹理名称,并且每个纹理将被放置在以后List使用该纹理名称访问.

c# enums list

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