我使用valgrindwith 检查了C++中的以下代码--leak-check=full,它说没有内存泄漏.这是为什么?
char *p = new char[256];
delete p;
Run Code Online (Sandbox Code Playgroud)
new[]delete[]据我所知应该匹配.
当我将编译器版本从gcc 4.6切换到gcc 4.8时,我得到以下错误错误:调用重载'isnan(double)'是不明确的.
这是因为在c ++ 11中有不同的函数声明:C:int isnan(double)C++ 11:bool isnan(double)
来自cpluplus:
我怎样才能解决这个问题?
我想将QtCreator设置为在unix中使用CRLF而不是LF.有没有办法做到这一点?
PS:我知道我可以在文件上使用dos2unix但是我不想这样做.
在C++中使用openMP时我再次陷入困境.这次我正在尝试实现并行快速排序.
码:
#include <iostream>
#include <vector>
#include <stack>
#include <utility>
#include <omp.h>
#include <stdio.h>
#define SWITCH_LIMIT 1000
using namespace std;
template <typename T>
void insertionSort(std::vector<T> &v, int q, int r)
{
int key, i;
for(int j = q + 1; j <= r; ++j)
{
key = v[j];
i = j - 1;
while( i >= q && v[i] > key )
{
v[i+1] = v[i];
--i;
}
v[i+1] = key;
}
}
stack<pair<int,int> > s;
template <typename T>
void …Run Code Online (Sandbox Code Playgroud) 我正在使用OpenGrok的替代品.我无法正确配置它.我想要的是浏览代码,就像我在Visual Studio中一样.我想要一个菜单,其中包含Go To Definition的最小选项,查找参考文献等.如何实现?
我在C中使用OpenMP 实现了并行冒泡排序算法(Odd-Even转置排序).然而,在我测试之后,它比串行版本慢了(大约10%),尽管我有一个4核处理器(2个真正的x 2,因为英特尔超线程).我已经检查了核心是否实际使用,我可以在运行程序时以100%的比例看到它们.因此我认为我在实现算法时犯了一个错误.
我使用linux与内核2.6.38-8-generic.
这是我编译的方式:
gcc -o bubble-sort bubble-sort.c -Wall -fopenmp 要么
gcc -o bubble-sort bubble-sort.c -Wall -fopenmp 对于串行版本
这就是我的运行方式:
./bubble-sort < in_10000 > out_10000
#include <omp.h>
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
int main()
{
int i, n, tmp, *x, changes;
int chunk;
scanf("%d ", &n);
chunk = n / 4;
x = (int*) malloc(n * sizeof(int));
for(i = 0; i < n; ++i)
scanf("%d ", &x[i]);
changes = 1;
int nr = 0;
while(changes)
{
#pragma …Run Code Online (Sandbox Code Playgroud) #include <iostream>
#include <string>
using namespace std;
class phonebook
{
string name;
string prefix;
public:
phonebook(string &name, string &prefix)
{
this->name = name;
this->prefix = prefix;
}
friend istream &operator>>(istream &in, phonebook &book);
};
istream &phonebook::operator>>(istream &in, phonebook &book)
{
in >> book.name >> book.prefix;
return in;
}
int main()
{
return 0;
}
Run Code Online (Sandbox Code Playgroud)
当我尝试使用g ++ 4.6.1编译此代码时:
"main.cpp:20:错误:'std :: istream&phonebook :: operator >>(std :: istream&,phonebook&)'必须只接受一个参数"
PS:这是非常愚蠢的事情......很明显:S.谢谢你.
我有以下文件:
main.c:
int f(void);
int main(void)
{
f();
return 0;
}
Run Code Online (Sandbox Code Playgroud)
FC:
char *f = "linker";
Run Code Online (Sandbox Code Playgroud)
GNUMakefile:
CC = gcc
CFLAGS = -Wall -g
all: main
main: main.o f.o
main.o: main.c
f.o: f.c
clean:
rm -rf *.o main
Run Code Online (Sandbox Code Playgroud)
运行makefile时,我没有收到编译警告/错误.为什么?
有没有办法让进程在Windows上更改其PID?我发现了这个问题[1],但它只针对Linux说明了答案(即"否").Windows怎么样?
[ 1 ] 更改linux中的进程ID
c++ ×4
c ×3
openmp ×2
bubble-sort ×1
c++11 ×1
gcc ×1
linker ×1
linux ×1
memory-leaks ×1
newline ×1
opengrok ×1
overloading ×1
process ×1
qt ×1
qt-creator ×1
quicksort ×1
valgrind ×1
windows ×1