编写函数我必须声明输入和输出数据类型,如下所示:
int my_function (int argument) {}
Run Code Online (Sandbox Code Playgroud)
有可能做出这样的声明,我的函数会接受int,bool或char类型的变量,并且可以输出这些数据类型吗?
//non working example
[int bool char] my_function ([int bool char] argument) {}
Run Code Online (Sandbox Code Playgroud) 每当新版本的浏览器出现时,我都会听到有关添加的新内容,比如说webGL和其他技术,没有人真正知道它们是否能够赶上.
但是我想知道是否有人在JS中考虑过类似散列函数(MD5,SHA1等)的基本内容.
最新的浏览器我的意思是今天的开发版本也很像Opera 12,Chrome 17或Firefox 10.
现在寻找解决方案我在这里发现了另一个帖子的评论:https://stackoverflow.com/questions/7204097/short-hashing-function-for-javascript(你知道javascript对象已经是哈希表吗?).那么这些'哈希表'是什么?这是否意味着我可以将任何字符串转换为哈希值,但不是像md5或sha1那样的已建立的字符串,而是某些特定的JS构建?
基本上我需要做的是:
var txt="Hello world!";
var hash = txt.toSha1();
Run Code Online (Sandbox Code Playgroud) 是否可以传入一个字符串流并让函数直接写入?
我记得我看到一个类似于这样的函数被调用:
my_func(ss << "text" << hex << 33);
Run Code Online (Sandbox Code Playgroud) 我真的不明白这一点,我认为编译器首先执行大括号中的内容然后将结果赋予最合适的函数.这看起来它给函数一个初始化列表来处理它...
#include <string>
#include <vector>
using namespace std;
void func(vector<string> v) { }
void func(vector<wstring> v) { }
int main() {
func({"apple", "banana"});
}
Run Code Online (Sandbox Code Playgroud)
错误:
<stdin>: In function 'int main()':
<stdin>:11:27: error: call of overloaded 'func(<brace-enclosed initializer list>)' is ambiguous
<stdin>:11:27: note: candidates are:
<stdin>:6:6: note: void func(std::vector<std::basic_string<char> >)
<stdin>:8:6: note: void func(std::vector<std::basic_string<wchar_t> >)
Run Code Online (Sandbox Code Playgroud)
为什么不func(vector<string> v)调用我的超载,我可以这样做吗?
我试过了,runemacs --user d:\path\to\init\.emacs但它给了
Error (initialization): Invalid user name d:\path\to\init\.emacs
我的意思是自定义位置中的自定义文件,例如我的pendrive等,而不是我在用户文件夹中的默认位置.我尝试为不同的配置创建具有相应init的cmd文件.
例如,我有这个数组:
int myArray[] = { 3, 6, 8, 33 };
Run Code Online (Sandbox Code Playgroud)
如何检查给定变量x是否在其中?
我是否必须编写自己的函数并循环数组,还是在现代c ++中与in_arrayPHP 相当?
是否有正则表达式替换函数将匹配发送到用户函数,然后替换返回值:
我尝试过这种方法,但显然不起作用:
cout << regex_replace("my values are 9, 19", regex("\d+"), my_callback);
Run Code Online (Sandbox Code Playgroud)
和功能:
std::string my_callback(std::string &m) {
int int_m = atoi(m.c_str());
return std::to_string(int_m + 1);
}
Run Code Online (Sandbox Code Playgroud)
结果应该是: my values are 10, 20
我的意思是类似于php preg_replace_callback或python的工作模式re.sub(pattern, callback, subject)
我的意思是最新的4.9 gcc,能够正常运行而无需提升.
我试过这个:
#include <map>
int main() {
static std::map<int,int> myMap = [](){
std::map<int,int> myMap;
return myMap;
};
}
Run Code Online (Sandbox Code Playgroud)
错误:
<stdin>: In function 'int main()':
<stdin>:8:3: error: conversion from 'main()::<lambda()>' to non-scalar type 'std::map<int, int>' requested
Run Code Online (Sandbox Code Playgroud)
是的,我知道我可以为它创建另一个"正常"函数,但是它可以运行,但是lambdas不能以这种方式初始化对象.
这是我尝试这样做的方式:
#include <stdio.h>
#include <windows.h>
using namespace std;
int main() {
SetConsoleOutputCP(CP_UTF8);
//german chars won't appear
char const* text = "aäbcdefghijklmnoöpqrsßtuüvwxyz";
int len = MultiByteToWideChar(CP_UTF8, 0, text, -1, 0, 0);
wchar_t *unicode_text = new wchar_t[len];
MultiByteToWideChar(CP_UTF8, 0, text, -1, unicode_text, len);
wprintf(L"%s", unicode_text);
}
Run Code Online (Sandbox Code Playgroud)
效果是只显示我们的ascii字符.没有显示错误.源文件以utf8编码.
那么,我在这里做错了什么?
到WouterH:
int main() {
SetConsoleOutputCP(CP_UTF8);
const wchar_t *unicode_text = L"aäbcdefghijklmnoöpqrsßtuüvwxyz";
wprintf(L"%s", unicode_text);
}
Run Code Online (Sandbox Code Playgroud)
第三步:
#include <stdio.h>
#define _WIN32_WINNT 0x05010300
#include <windows.h>
#define _O_U16TEXT 0x20000
#include <fcntl.h>
using namespace std;
int main() { …Run Code Online (Sandbox Code Playgroud) 例:
$string = "This is some text written on 2010-07-18.";
preg_match('|(?<date>\d\d\d\d-\d\d-\d\d)|i', $string, $arr_result);
print_r($arr_result);
Run Code Online (Sandbox Code Playgroud)
返回:
Array
(
[0] => 2010-07-18
[date] => 2010-07-18
[1] => 2010-07-18
)
Run Code Online (Sandbox Code Playgroud)
但我希望它是:
Array
(
[date] => 2010-07-18
)
Run Code Online (Sandbox Code Playgroud)
在PHP的PDO对象中,有一个选项可以通过删除这些重复的编号值来过滤数据库中的结果:PDO::FETCH_ASSOC.但我还没有看到PHP中PCRE函数的类似修饰符.