我做了这样的事情,但没有工作.base48Encode方法参数我以毫秒为单位通过了当前系统时间
private static final String CHARACTER_SET = "23456789abcdefghijkmnpqrstuvwxyzABCDEFGHIJKLMNPQRSTUVWXYZ";
public static String base48Encode(double d) {
Double num = Double.valueOf(d);
Integer length = CHARACTER_SET.length();
String encodeString = new String();
while (num > length) {
encodeString = CHARACTER_SET.charAt(num.intValue() % length) + encodeString;
num = Math.ceil(new Double(num / length) - 1);
}
encodeString = CHARACTER_SET.charAt(num.intValue()) + encodeString;
return encodeString;
}
Run Code Online (Sandbox Code Playgroud) 我正在查看第五版C++ Primer中的代码示例.在页512上,他们提供operator=如下示例代码:
HasPtr& HasPtr::operator=(const HasPtr &rhs)
{
auto newp = new string(*rhs.ps); // copy the underlying string
delete ps; // free the old memory
ps = newp; // copy data from rhs into this object
i = rhs.i;
return *this; // return this object
}
Run Code Online (Sandbox Code Playgroud)
他们正确地争辩说,如果按照这个顺序做事,即使是自我分配,事情也会正常.但是,我一直看到检查是明确完成的建议:
HasPtr& HasPtr::operator=(const HasPtr &rhs)
{
if (&rhs == this) return *this; // early exit if self assignment
auto newp = new string(*rhs.ps); // copy the underlying string
delete ps; // free the …Run Code Online (Sandbox Code Playgroud) 以下 C++ 代码(按原样)来自http://rosettacode.org/wiki/Entropy。有错误 - 有人可以纠正吗?
#include <string>
#include <map>
#include <iostream>
#include <algorithm>
#include <cmath>
double log2( double number ) {
return log( number ) / log( 2 ) ;
}
int main( int argc , char *argv[ ] ) {
std::string teststring( argv[ 1 ] ) ;
std::map<char , int> frequencies ;
for ( char c : teststring )
frequencies[ c ] ++ ;
int numlen = teststring.length( ) ;
double infocontent = 0 ;
for ( …Run Code Online (Sandbox Code Playgroud) 我有一个字符串数组,我根据空白区域拆分.现在,根据我的要求,我必须得到其内容中包含'/'的数组元素,但我无法得到它.我不明白如何实现它.
这是我尝试过的代码:
string[] arrdate = currentLine.Split(' ');
Run Code Online (Sandbox Code Playgroud)
如何获取由/?组成的数组元素?