小编Tom*_*ica的帖子

将SDL库添加到我的程序中

关于这一点已经有几个问题了,但是,让我们说,所有的问题都高于我.我只知道有一些下载链接在这里和我应该下载SDL-1.2.15-win32-x64.zip(64位Windows) ,以配合我的系统和SDL-devel的-1.2.15-mingw32.tar.gz (Mingw32)匹配我的编译器.怎么办?开发档案包含一些C++项目,我不知道,我应该怎么做.要包含哪些文件?链接器中要链接的文件是什么?

编辑:

信息

系统:Windows 7x64
IDE:Code :: Blocks编译器:G ++

c++ sdl

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

当字符串大小无关紧要时,为什么strlen()比使用变量慢?

我正在编写一些简单的文件操作,如果我将字符串大小保存在变量中会不会更快,我会想到一个想法.它表明它快了10倍.
使用此代码:

include "../classes/Timer.class.php";
$t = new Timer();             //Timer class I've written for this purpose [link below]
$multiplyer = 3000000;        //Times to try the operation
$string = str_repeat("ggggggggggg",2);  //I first tried 2000 here, but for 2 there are same results
$t("calling");     //Saving time
for($i=0; $i<$multiplyer; $i++) {
  $size =  strlen($string);
  $size2 = strlen($string);
  $size3 = strlen($string);
}
$t("clover");
$t("caching");     //Saving time
for($i=0; $i<$multiplyer; $i++) {
  $size =  strlen($string);
  $size2 = $size;
  $size3 = $size;
}
$t("chover");
$total = $t["calling-clover"]+$t["caching-chover"];  //percents …
Run Code Online (Sandbox Code Playgroud)

php performance strlen

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

将没有默认构造函数的类设为另一个类的私有属性

我正在尝试创建一个使用 Boost 套接字进行操作的类,以使连接易于使用。
我的SocketClient班级有一些属性,boost::asio::ip::tcp::socket就是其中之一。但我的构造函数中出现C2512错误,因为boost::asio::ip::tcp::socket它没有构造函数,因此不能存在统一化。
在这里,看一下该类的代码:

class SocketClient {
private:
    int port;    //Port, currently unused
    boost::asio::io_service io_service;  
    boost::asio::ip::tcp::resolver::iterator endpoint_iterator;  
    boost::asio::ip::tcp::socket sock;  //This causes the error
    //It wants to be like this (impossible too):
  //boost::asio::ip::tcp::socket sock(io_service);
public:
    void init(const char*, const char* );
    SocketClient();  //Default constructor
    bool connect();
    bool read(int bytes, char *text);
    bool send(int length, char *text);
    bool send(std::string text);
    unsigned int timeout;
};
Run Code Online (Sandbox Code Playgroud)

这是构造函数:

SocketClient::SocketClient() {  //ERROR: (23): error C2512: 'boost::asio::basic_stream_socket<Protocol>' : …
Run Code Online (Sandbox Code Playgroud)

c++ oop constructor boost-asio

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

使用javascript选择具有相同标签名称的所有元素,并部分突出显示内容

我做了一个代码,应该突出搜索字符串,但它不起作用.
这是代码:

<body>

  <div>div is here</div>
   <div id="divid">

    <div>this is a div 1</div>
    <div> this is a div 2</div>
    <div> this is a div3</div>

  </div>

  <div> another div is here</div>
  </body>  
Run Code Online (Sandbox Code Playgroud)

这是一个javascript代码.

  function checkit(){

var hlWord = "div";
        var nregex = new RegExp(hlWord,"gi");
        var div = document.getElementById("divid").getElementsByTagName('div');

        for(var i=0; i <= div.length; i++){

            var div1 = div[i].innerHTML;

            var rword = div1.replace(nregex,"<b>"+hlWord+"</b>");
            div1.innerHTML = rword;

        }


  }  
Run Code Online (Sandbox Code Playgroud)

html javascript highlight

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

autosave属性应该做什么?我该如何使用它?

我一直在查找新的HTML5表单属性,以了解如何为移动设备制作页面.在阅读时,我遇到了"自动保存"属性.

我一直在测试它但没有发生任何事情.它的目的是什么?我的代码是否正确?它甚至与搜索有关,还是我误解了MDN?

自动保存
此属性应定义为唯一值.如果type属性的值为search,则之前的搜索词值将在页面加载的下拉列表中保留.

我的代码:

<form method="POST">
    <input type="search" name="fieldxxx" autosave="unique666" required="true" autocomplete="off"/>
    <button type="submit">Search</button>
</form>
Run Code Online (Sandbox Code Playgroud)

documentation html5

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

如何将8个方向映射到1D阵列

屏幕上有8个方向的8个光标.

屏幕上的指示

我想将它们放入数组并根据方向向量选择它们.顺序无关紧要,但我需要为i上面看到的每个向量分配1D数组中的坐标.我花了很长时间试图为它创造出公式,但没有任何方法可行.

矢量中的值可以是0,1,-1.

伪代码:

Cursor getCursor(int x, int y) {
    int i = TheFunctionINeed(x,y);
    return cursors[i];
}
Run Code Online (Sandbox Code Playgroud)

注意:因为很多人对我想要的东西感到困惑,所以我使用了答案来制作以下小提琴:将矢量映射到数组.

c# arrays math

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

在屏幕上轻松打印图像以便以阻止方式进行调试

我正在研究一个计算机视觉项目,并在某个过程中发生无限循环.我的图像数据似乎已被破坏.

过去,我曾经使用这种方法在磁盘上保存调试结果:

   public static boolean saveToPath(String path, BufferedImage image) {
     File img = new File(path);
     try {
       ImageIO.write(image, "png", new File(path));
     } catch (IOException ex) {
       System.err.println("Failed to save image as '"+path+"'. Error:"+ex);
       return false;
     }
     return true;
   }
Run Code Online (Sandbox Code Playgroud)

问题是,一旦使用循环并且错误介于两者之间,我需要看到许多图像.所以基本上,我想要一个像这样定义的方法:

  /** Displays image on the screen and stops the execution until the window with image is closed.
   * 
   * @param image image to be displayed
   */
public static void printImage(BufferedImage image) {
   ???
}
Run Code Online (Sandbox Code Playgroud)

并且可以在循环或任何函数中调用以显示实际图像,有效地表现为断点.因为虽然多线程在生产代码中非常好,但阻塞函数对于调试来说要好得多.

java debugging bufferedimage

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

SYSTEM_INFORMATION_CLASS在哪里定义?

我遇到了一个简短的C++代码,旨在防止应用程序使用DL​​L注入窃取焦点.和C++一样,我遇到的问题是未定义的东西和缺少的库.

具体来说,这个常数是未定义的:SYSTEM_INFORMATION_CLASS.在这段代码中:

typedef NTSTATUS( WINAPI* PNT_QUERY_SYSTEM_INFORMATION ) ( 
  __in       SYSTEM_INFORMATION_CLASS SystemInformationClass,     
  __inout    PVOID SystemInformation, 
  __in       ULONG SystemInformationLength, 
  __out_opt  PULONG ReturnLength    
);
Run Code Online (Sandbox Code Playgroud)

windows.h已经包含,所以它必须是别的东西丢失.当谷歌搜索时,我得到了很多关于获得CPU温度的结果,但是我看不出它应该包括在内...

c++ winapi

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

我可以在不嵌套try语句的情况下尝试多种方法吗?

我的程序正在处理一些JSON数据.我希望程序在一段时间内保持稳定,JSON数据可以随着源的更新和改进而改变.这是从数据中返回一些图像文件名的当前函数:

@Override
public String createImgName() {
  try {
    // data["image"]["full"]
    return getJSONData().getJSONObject("image").getString("full");
  }
  catch(JSONException e) {
    try {
      // data["id"] + ".png"
      return  getJSONData().getJSONObject("id")+".png"; 
    }
    catch(JSONException e2) {
      return null;
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

还有一些我try可以获得图像名称的东西.但该计划将变得非常丑陋.

try成功之前是否存在多种事物的语法?在我的情况下,该return声明打破了成功的程序,但可能并非总是如此.

java exception-handling try-catch

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

无法将参数1从'const boost :: shared_mutex'转换为'const boost :: shared_lock &lt;Mutex&gt;&'

我只是想用100多个upvotes来实现有关互斥的答案。我所做的就是复制粘贴代码,以便我的班级像这样读取(简化):

mymutexclass.h

class MyMutexClass {
public:
    void write( uint32_t id, const std::string &str );
    std::string read( uint32_t id ) const;

private:
    boost::shared_mutex _access;
    std::map<uint32_t, std::string> strings;
};
Run Code Online (Sandbox Code Playgroud)

mymutexclass.cpp

void MyMutexClass::write( uint32_t id, const std::string &str ) {
    boost::unique_lock< boost::shared_mutex > lock(_access);
    strings[id] = name;
}
std::string MyMutexClass::read( const uint32_t id ) const {
    boost::shared_lock< boost::shared_mutex > lock(_access); // ERROR HERE
    if( strings.count( id )>0) 
        return strings.at(id);
    else
        return "No value.";
}
Run Code Online (Sandbox Code Playgroud)

而且我得到一个错误,仅针对读取的互斥行:

error C2664: …
Run Code Online (Sandbox Code Playgroud)

c++ boost visual-studio-2010 c++11

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