从源(Files,InputStreams,URLs)读取图像最方便的方法是:
BufferedImage myImage = ImageIO.read( source );
Run Code Online (Sandbox Code Playgroud)
但是,如何转换myImage为BufferedImage.TYPE_USHORT_565_RGB格式?
是否可以为std :: cin设置超时?例如,std :: cin在10秒内没有收到任何数据 - 它会抛出异常或返回错误.
编辑:
那计时器Boost library呢?据我所知,它是便携式库.是否有可能要求Boost库的计时器在预定义的时间段后抛出异常?我想它可以解决这个问题.
我在Ubuntu-Linux 11.10的平台上开发了一个小型的cpp程序.现在我想对它进行逆向工程.我是初学者.我使用这样的工具:GDB 7.0,hte编辑器,hexeditor.
这是我第一次轻松搞定.在符号信息的帮助下,我创建了主要功能的地址,并完成了我需要的一切.然后我条纹(--strip-all)可执行的elf文件,我有一些问题.我知道main这个程序中的函数从0x8960开始.但我不知道如果没有这方面的知识我怎么能找到这一点.我试着调试一步用gdb我的程序一步,但它进入 __libc_start_main
然后进入ld-linux.so.3(所以,它找到并加载一个程序运行所需的共享库).我调试了大约10分钟.当然,可能在20分钟内我可以到达主要功能的切入点,但似乎更容易存在.
如何在main没有任何符号信息的情况下找到函数的入口点?在gdb的帮助下,您能否通过elf文件的逆向工程向我推荐一些好的书籍/网站/ other_sources?任何帮助,将不胜感激.
我的代码从文本文件中读取unsigned int变量Input_File_Name.
unsigned int Column_Count; //Cols
unsigned int Row_Count;//Rows
try {
ifstream input_stream;
input_stream.open(Input_File_Name,ios_base::in);
if (input_stream) {
//if file is opened
input_stream.exceptions(ios::badbit | ios::failbit);
input_stream>>Row_Count;
input_stream>>Column_Count;
} else {
throw std::ios::failure("Can't open input file");
//cout << "Error: Can't open input file" << endl;
}
} catch (const ios::failure& error) {
cout << "Oh No!!" << error.what() << endl;
} catch (const exception& error) {
cout << error.what() <<"Oh No!!" << endl;
} catch (...) {
cout << "Unknown …Run Code Online (Sandbox Code Playgroud) 我有一个简单的C程序 "./my_program"
#include <stdio.h>
int main (int argc , char **argv) {
unsigned int return_result = 0x474;
printf("return_result = %d = 0x%x \n",return_result,return_result);
return return_result;
}
Run Code Online (Sandbox Code Playgroud)
结果,该程序打印:
return_result = 1140 = 0x474
Run Code Online (Sandbox Code Playgroud)
我想在bash脚本中获得c-program的返回值.根据这个链接 无论如何从命令行获取c程序的返回值? 我应该从$得到这个变量?
但是当我发起这样的命令后果:
./my_program
echo $?
Run Code Online (Sandbox Code Playgroud)
我明白了
116
Run Code Online (Sandbox Code Playgroud)
很明显,116 = 0x74(最低字节).但我想获得整个unsigned int值.怎么了?我该怎么做才能从命令行获取c-program的整个返回值?这不仅仅是"unsigned int"类型.如果我创建了一些复杂的类型,我应该怎么做,例如, - 结构.
我试过这个:
return ((unsigned int) return_result_section_size);
Run Code Online (Sandbox Code Playgroud)
它不起作用.
我有这样一个程序:
#include <stdlib.h>
#include <iostream>
static int pswd=0;
int main() {
do {
std::cout<<"I need your password:"<<std::endl;
std::cin>>pswd;
} while (pswd!=3855);
std::cout<<"Congratulations! Your password is correct! Your soul is free again!"<<std::endl;
}
Run Code Online (Sandbox Code Playgroud)
我可能是一个愚蠢的问题.当我输入无效值(非数字符号或大于int的值)时,程序进入无限循环而不从控制台读取任何信息.
I need your password:
I need your password:
I need your password:
I need your password:
I need your password:
I need your password:
I need your password:
I need your password:
I need your password:
I need your password:
I need your password:
I need your …Run Code Online (Sandbox Code Playgroud) 我需要提升我的 python 应用程序。解决方案应该是微不足道的:
import time
from multiprocessing import Pool
class A:
def method1(self):
time.sleep(1)
print('method1')
return 'method1'
def method2(self):
time.sleep(1)
print('method2')
return 'method2'
def method3(self):
pool = Pool()
time1 = time.time()
res1 = pool.apply_async(self.method1, [])
res2 = pool.apply_async(self.method2, [])
res1 = res1.get()
res2 = res2.get()
time2 = time.time()
print('res1 = {0}'.format(res1))
print('res2 = {0}'.format(res2))
print('time = {0}'.format(time2 - time1))
a = A()
a.method3()
Run Code Online (Sandbox Code Playgroud)
但是每次我启动这个简单的程序时,我都会遇到一个异常:
Exception in thread Thread-2:
Traceback (most recent call last):
File "/usr/lib/python3.2/threading.py", line 740, in _bootstrap_inner
self.run() …Run Code Online (Sandbox Code Playgroud) 我的任务是在矩阵中找到从一个点到另一个点的最短路径.可以仅在这样的方向上移动(向上,向下,向左,向右).
0 0 0 0 1 0 0 0
1 0 0 0 0 0 0 0
0 0 0 1 0 1 F 0
0 1 0 1 0 0 0 0
0 0 0 1 0 0 0 0
0 S 0 1 0 0 1 0
0 0 0 0 0 0 1 0
0 0 0 0 0 0 1 0
Run Code Online (Sandbox Code Playgroud)
S - 起点
F - 目的地(完成)
0 - 免费细胞(我们可以穿过它们)
1 - "墙壁"(我们不能穿过它们)
很明显,广度优先搜索以最佳方式解决了这个问题.我知道Boost库提供了这个算法,但我之前没有Boost.
如何使用Boost在我的案例中进行广度优先搜索?据我所知,Boost的广度优先搜索算法仅适用于图形.我想将矩阵转换为带m*n …
我有一个双子座:
deque<char> My_Deque;
My_Path.push_front('a');
My_Path.push_front('b');
My_Path.push_front('c');
My_Path.push_front('d');
My_Path.push_front('e');
Run Code Online (Sandbox Code Playgroud)
有这样的方法输出它.
首先:
deque<char>::iterator It;
for ( It = My_Deque.begin(); It != My_Deque.end(); It++ )
cout << *It << " ";
Run Code Online (Sandbox Code Playgroud)
第二:
for (i=0;i<My_Deque.size();i++) {
cout << My_Deque[i] << " ";
}
Run Code Online (Sandbox Code Playgroud)
什么是访问双端队列的元素的最佳途径-通过迭代器或类似这样的:My_Deque[i]?deque <...>元素是一个指向每个元素的指针数组,用于快速访问它的数据,或者以连续的方式提供对它的随机元素的访问(如下图所示)?
我在 readelf 实用程序的帮助下打开了我的对象 elf 文件: readelf -a ./my_object.o | less 结果我得到了很多有趣的信息。我在节表中看到了带有“GROUP”类型的“.group”节。有人可以解释一下,“.group”部分的任命是什么吗?
对于小程序,我们可以通过这种方式防止内存泄漏:
proc() {
//allocate memory for matrix
try {
}
catch {
//free matrix memory
}
...
//free matrix memory
}
Run Code Online (Sandbox Code Playgroud)
如果我们的程序更复杂:
proc() {
//allocate memory for matrix
try {
}
catch {
//free matrix memory
}
...
try {
}
catch {
//free matrix memory
}
...
try {
}
catch {
//free matrix memory
}
...
//free matrix memory
}
Run Code Online (Sandbox Code Playgroud)
它看起来有点笨拙.是一种更好的方法,更好的编程风格是否存在内存泄漏控制?据我所知,C++有auto_ptr,我们可以开发程序而不需要关心内存释放.
proc() {
//allocate auto_ptr
try {
}
catch {
}
...
}
Run Code Online (Sandbox Code Playgroud)
但是,据我所知,auto_ptr甚至不适用于数组.因此,在一般情况下,这是不可接受的方式.
我有一个模板结构:
template<typename T2, class, typename, class T3 = vec1<T2> >
struct vec2
{
template<typename D2, class, typename, class D3>
void f14(int a);
template<typename D2, class, typename, class D3>
void f15(int a);
};
Run Code Online (Sandbox Code Playgroud)
我想定义,例如函数f15.我不知道,我应该在"??"的地方写些什么.我尝试以不同的方式解决这个问题.但是编译器杀了我的梦想来编译我的程序.
template<typename T2, class , typename , class T3>
template<typename D2, class , typename , class D3>
void vec2<T2,??,??,T3>::f15(int a) { }
Run Code Online (Sandbox Code Playgroud)
我该如何定义函数f15?
这类结构"class,typename"的学名是什么?我搜索了很多("未命名的模板参数"等等),但我没有发现任何相关信息.我猜,它与未命名的参数相似.我想读一些关于它的内容 - 来自C++标准或其他来源,但我不知道必要信息在哪里.