由于Android开发人员建议使用HttpURLConnection该类,我想知道是否有人可以为我提供一个很好的示例,说明如何通过POST将位图"文件"(实际上是内存中的流)发送到Apache HTTP服务器.我对cookie或身份验证或任何复杂的东西不感兴趣,但我只想拥有一个可靠的逻辑实现.我在这里看到的所有例子看起来更像是"让我们试试这个,也许它有效".
现在,我有这个代码:
URL url;
HttpURLConnection urlConnection = null;
try {
url = new URL("http://example.com/server.cgi");
urlConnection = (HttpURLConnection) url.openConnection();
} catch (Exception e) {
this.showDialog(getApplicationContext(), e.getMessage());
}
finally {
if (urlConnection != null)
{
urlConnection.disconnect();
}
}
Run Code Online (Sandbox Code Playgroud)
showDialog应该只显示一个AlertDialog(如果URL无效?).
现在,让我们说我生成一个这样的位图:Bitmap image = this.getBitmap()在一个派生的控件中View,我想通过POST发送它.实现这样的事情的正确程序是什么?我需要使用哪些课程?我可以HttpPost在这个例子中使用吗?如果是这样,我将如何构建InputStreamEntity我的位图?我觉得要首先将位图存储在设备上的文件中是令人反感的.
我还要提一下,我真的需要将原始位图的每个未经改变的像素发送到服务器,因此我无法将其转换为JPEG.
我正在阅读关于"五条规则"的这个很好的答案,我注意到一些我以前没有记得的事情:
class C {
...
C& operator=(const C&) & = default;
C& operator=(C&&) & = default;
...
};
Run Code Online (Sandbox Code Playgroud)
&放置在= default复制赋值运算符和移动赋值运算符前面的字符的用途是什么?有没有人有这方面的参考?
JMX的目的是什么?它用于什么?我一直在浏览JMX上的一些教程,他们所做的只是注册一些Mbeans并从jconsole调用那些Mbeans.如果这是它的目的,那么JMX和RMI(远程过程调用)之间有什么区别?
提前致谢!
我在C-SVC模式下使用libsvm,使用2阶多项式内核,我需要训练多个SVM.在训练过程中,我为一些我训练的SVM得到了一个甚至两个警告:
WARNING: using -h 0 may be faster
*
WARNING: reaching max number of iterations
optimization finished, #iter = 10000000
Run Code Online (Sandbox Code Playgroud)
我找到了h参数的描述:
-h shrinking : whether to use the shrinking heuristics, 0 or 1 (default 1)
Run Code Online (Sandbox Code Playgroud)
我试图阅读libsvm文档中的解释,但对我来说这有点太高了.任何人都可以提供一个外行的解释,或许,一些建议,如设置这将是有益的,因为......?此外,如果通过为我训练的所有SVM设置此参数,可能会对那些未明确发出此警告的SVM的准确性产生负面影响,将会很有帮助.
我不知道该怎么做其他警告.
只是为了提供更多细节:我的训练集有10个属性(特征),它们由5000个向量组成.
更新:
如果其他人获得"达到最大迭代次数",则似乎是由数值稳定性问题引起的.而且,这将产生非常慢的训练时间.多项式内核确实受益于使用交叉验证技术来确定正则化的最佳值(C参数),并且在多项式内核的情况下,对我来说它有助于保持小于8.此外,如果内核是不均匀的\ sum(\ gamma x_i s_i + coef0)^ d(对不起,SO不支持LaTeX),其中coef0!= 0,然后交叉验证可以使用网格搜索技术实现gamma和C,因为,在此例如,gamma(1/number_of_features)的默认值可能不是最佳选择.尽管如此,根据我的实验,你可能不希望gamma太大,因为它会导致数字问题(我正在尝试最大值为8).
为了进一步了解gamma和C的可能值,我们应该尝试在grid.py中进行挖掘.
可能重复:
通过隐式转换为字符串来流对象时,重载决策失败
我知道这样做并不是一个好主意,但我真的想知道下面的代码无法编译的原因(即为什么"没有可接受的转换"):
#include <iostream>
#include <string>
class Test
{
public:
operator std::string () const;
};
Test::operator std::string () const
{
return std::string("Test!");
}
int main ()
{
std::string str = "Blah!";
std::cout << str << std::endl;
Test test;
str = test;//implicitly calls operator std::string without complaining
std::cout << str << std::endl;
std::cout << test;//refuses to implicitly cast test to std::string
return 0;
}
Run Code Online (Sandbox Code Playgroud)
在Visual Studio 2010上,我收到此错误:" error C2679: binary '<<' : no operator found which takes a right-hand operand …
编辑:继迈克·西摩的评论,我换成operator std::string () const;用operator char * () const;,并相应地改变了实现.这允许隐式转换,但是,由于某种原因,unsigned long int运算符优先于char*运算符,这只是感觉不对...而且,我不想暴露讨厌的C之类的东西,比如char*class,当我有std :: string时.我有一种预感,我的CustomizedInt类需要继承一些东西才能支持我想要的功能.有人可以详细说明迈克的评论std::basic_string吗?我不确定我是否理解得当.
我有这段代码:
#include <string>
#include <sstream>
#include <iostream>
class CustomizedInt
{
private:
int data;
public:
CustomizedInt() : data(123)
{
}
operator unsigned long int () const;
operator std::string () const;
};
CustomizedInt::operator unsigned long int () const
{
std::cout << "Called operator unsigned long int; ";
unsigned long int output;
output = (unsigned long int)data;
return output;
}
CustomizedInt::operator std::string () const
{ …Run Code Online (Sandbox Code Playgroud) -Wconversion编译此程序时,GCC参数会从标题中生成警告:
#include <iostream>
#include <array>
#include <string>
int main ()
{
std::string test = "1";
std::array<unsigned char, 1> byteArray;
byteArray[0] = byteArray[0] | test[0];
return 0;
}
Run Code Online (Sandbox Code Playgroud)
这是我如何编译它:g++- -Wall -Wextra -Wconversion -pedantic -std=c++0x test.cpp我正在使用GCC 4.5.
我在这里做违法的事吗?在某些情况下会引起问题吗?为什么产品会|产生int?
如何使用SQL查询获取MS SQL Server(2012)列出的所有系统存储过程?
我试图有一个允许隐式转换为某些内置类型的类,比如unsigned long int,因为我试图尽可能正确地做这个(这是我在C++中的第一个重要项目),我遇到了一个奇怪的关于const正确性的问题:
这有效:
#include <iostream>
class CustomizedInt
{
private:
int data;
public:
CustomizedInt();
CustomizedInt(int input);
operator unsigned long int () const
{
unsigned long int output;
output = (unsigned long int)data;
return output;
}
};
CustomizedInt::CustomizedInt()
{
this->data = 0;
}
CustomizedInt::CustomizedInt(int input)
{
this->data = input;
}
int main()
{
CustomizedInt x;
unsigned long int y = x;
std::cout << y << std::endl;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
但是这个:
#include <iostream>
class CustomizedInt
{
private:
int data;
public:
CustomizedInt();
CustomizedInt(int …Run Code Online (Sandbox Code Playgroud) 即使在这里多次讨论过这个问题,我也无法找到关于我的具体案例的确凿解释.会const延长RefTest临时的寿命吗?以下示例是合法的吗?
#include <iostream>
class RefTest
{
public:
RefTest(const std::string &input) : str(input) {}
~RefTest () {std::cout << "RefTest" << std::endl;}
private:
std::string str;
};
class Child
{
public:
Child (const RefTest &ref) : ref_m(ref) {}
~Child () {std::cout << "Test" << std::endl;}
private:
const RefTest &ref_m;
};
class Test
{
public:
Test () : child(RefTest("child")) {}//Will the temporary get destroyed here?
~Test () {std::cout << "Test" << std::endl;}
private:
const Child child;
};
int main () …Run Code Online (Sandbox Code Playgroud)