小编Omk*_*kar的帖子

检查安装的mingw平台,32位或64位

我用c ++编程.我安装了mingw.我是从mingw网站的标准安装程序安装的.我在mingw32,mingw,mingw64之间感到困惑.有什么区别,如何查看我的版本.当我的程序构建时,我怎么知道创建的可执行文件是32位还是64位?

exe mingw

11
推荐指数
2
解决办法
3万
查看次数

OpenMP关键部分vs锁

OpenMP锁和临界区有什么区别?它们只是彼此的替代品吗?例如,如果我使用多个文件写入同一个文件,我应该在写入文件之前使用锁定还是仅使用临界区?

openmp

6
推荐指数
1
解决办法
3373
查看次数

双指针vs通过引用指针传递

在理解双指针概念及其应在何处使用时,我对此表示怀疑。我对这段代码进行了实验,发现我也可以使用按引用传递指针来代替双指针。

#include<iostream>
using namespace std;
void modify_by_value(int* );
void modify_by_refrence(int* &);
int a=4, b=5;
void main()
{

    int *ptr = NULL;
    ptr = &a;       
    cout << "*ptr before modifying by value: " << *ptr << endl; 
    modify_by_value(ptr);
    cout << "*ptr after modifying by value: " << *ptr << endl;
    cout << "*ptr before modifying by refrence: " << *ptr << endl;
    modify_by_refrence(ptr);
    cout << "*ptr after modifying by refrence: " << *ptr << endl;

}
void modify_by_value(int* ptr)      //this function …
Run Code Online (Sandbox Code Playgroud)

c++ pointers

5
推荐指数
1
解决办法
4261
查看次数

为什么我不能直接为指针分配返回的引用?

我已经声明geta()函数返回对a的引用,我必须在int指针中收集它.代码工作正常,但为什么我不能使用注释行.是不是在做同样的事情?代码如下:

#include<iostream>
using namespace std;
class Foo
{
    int a=6;
public:
    int& geta()
    {
        return a;
    }
};
int main()
{
    Foo f;
    int &z = f.geta();          //int *p = f.geta();  Why this doesn't work?
    int *p = &z;
    cout << *p;
}
Run Code Online (Sandbox Code Playgroud)

c++ pointers

0
推荐指数
1
解决办法
1267
查看次数

一个用c ++打印矢量和列表的函数

在学习标准模板库时

/*
Aim:Create a vector of integers. Copy it into a list, reversing as you 
do so.
*/

#include<iostream>
#include<vector>
#include<algorithm>
#include<list>
using namespace std;
template<typename t>
void print(vector <t> &v)      //what changes need to be done here?
{
    for (auto it = v.begin(); it < v.end(); it++)
    {
        cout << *it << " ";
    }
    cout << endl;
}
int main()
{
    vector<int> v;
    v.push_back(1);
    v.push_back(2);
    v.push_back(3);
    v.push_back(4);
    print(v);         
    list<int> l(v.size());
    reverse_copy(v.begin(), v.end(), l.begin());
    print(l);        //cannot call this
} …
Run Code Online (Sandbox Code Playgroud)

c++ stl

0
推荐指数
1
解决办法
1344
查看次数

c ++ STL remove-if算法和擦除算法问题.

目的:创建一个向量.在它上面使用remove_if

#include<iostream>
#include<vector>
#include<iterator>
#include<algorithm>
#include<functional>
using namespace std;
int main()
{
    int negative_count=0;
    vector<int> v = { 2, -1, -3, 5, -5, 0, 7 };
    copy(v.begin(), v.end(), ostream_iterator<int>(cout, " "));
    cout << endl;

    vector<int>::iterator new_it=remove_if(v.begin(), v.end(), bind2nd(greater<int>(), -1));
    v.erase(new_it);
    copy(v.begin(), v.end(), ostream_iterator<int>(cout, " "));
    cout << endl;


}
Run Code Online (Sandbox Code Playgroud)

输出:产量

remove_if条件是删除大于-1的数字.为什么显示-5两次?remove_if之后的输出应该是-1 -3 -5 5 0 7.如果我使用的话

V.erase(new_int,v.end())
Run Code Online (Sandbox Code Playgroud)

输出很好:-1 -3 -5

c++ stl vector

0
推荐指数
1
解决办法
199
查看次数

标签 统计

c++ ×4

pointers ×2

stl ×2

exe ×1

mingw ×1

openmp ×1

vector ×1