std

    -1热度

    1回答

    我有一个特殊的回调(这是在一些'C'土地定义)需要填充一些额外的工作,不属于回调函数的一部分。它是这样的...... typedef void (*callback_func)(int); extern int set_callback(callback_func cb); 在我的C++代码,我需要SET_VALUE是回调的范围之外定义,在我的课的承诺。所以,我必须捕获std :: prom

    0热度

    1回答

    我想在函数err_fun中,当离开err_fun()时,堆栈em会自由,所以em的内容会在同一时间自由释放,为什么 我仍然可以在栈函数的主函数中得到正确的答案。 感谢。 #include <stack> stack<int> st; void err_fun() { stack<int> em; st.swap(em); } int main() { e

    -3热度

    1回答

    这是我的代码。 std::ifstream file(filePath, std::ios::binary); if (file.fail()); { fatalError("File could not be opened."); } 这不会给我一个生成错误,但它不想打开文件。我正在尝试打开一个PNG文件,但每次都会失败。

    -1热度

    1回答

    编辑: 代码应该没问题...是上游代码问题。 谢谢大家! 原题: 我发现了一个代码示例从 Replace part of a string with another string 而且我做了一些改变(编辑): bool replace(std::wstring& str, const std::wstring& from, const std::wstring& to) { size_t sta

    2热度

    1回答

    由于一些要求,我需要通过一个字符串来走走看看,如果字符串中存在任意数量。 当我尝试下面的代码,我的测试过程中,应用程序崩溃。经过仔细的观察,我注意到,输入字符串包含特殊字符(扩展ASCII字符数).. #include <iostream> #include <string> #include <algorithm> int main() { std::string words

    6热度

    2回答

    C++标准库提供将比较器传递给std::sort。但是,在我的代码中,我有很多情况下我想通过函数f对T对象列表进行排序。像这样的比较器将是一个有效的选择: bool compare(const T& a, const T& b) { return f(a) < f(b); } 虽然这并不是最佳选择。 f评估速度较慢,但​​对于具有相同T对象的每次调用都会返回相同的值。所以我宁愿做的

    1热度

    1回答

    我的任务是实现我自己的std :: ref函数。我知道有一个reference_wrapper函数,它有助于std :: ref。但我怎么能实现这些功能/类。我想到以下内容: template <class T> struct myreference_wrapper{ T& functor; myreference_wrapper(T& t):functor(t){}

    -3热度

    1回答

    我一直对微软的Visual C++ 2010(32位系统) 在编译阶段我得到一个错误,指出: 1>------ Build started: Project: pruebavecot, Configuration: Debug Win32 ------ 1> pruebavecot.cpp 1>c:\users\andresgraco\desktop\pruebavecot\pruebavec

    0热度

    1回答

    例如我有一个使用double作为数据类型的2D数组。 vector<vector<double> > array2D; // Set up sizes. (HEIGHT x WIDTH) array2D.resize(HEIGHT); for (int i = 0; i < HEIGHT; ++i) array2D[i].resize(WIDTH); 我该如何定义迭代器,它可

    -2热度

    2回答

    我想创建一个std :: discrete_distribution离散分布: http://en.cppreference.com/w/cpp/numeric/random/discrete_distribution 所有的例子我见过定义它像上面的链接std::discrete_distribution<> d({40, 10, 10, 40}); 但是,相反的{40, 10, 10, 40}我