代码:
for(x=abc.begin();x!=abc.end();x++)
{
if(-----)
{
----
abc.erase(x);
}
}
Run Code Online (Sandbox Code Playgroud)
错误是:::
Dangerous iterator用法
擦除后迭代器无效,因此解除引用或将其与另一个迭代器进行比较无效.
在上面的代码中使用擦除功能的错误用法是什么?
我正在编写一个程序,使用mmap分配大量内存,然后访问随机内存位置以读取和写入.我刚刚尝试了以下代码:
#include <stdio.h>
#include <stdlib.h>
#include <sys/mman.h>
int main() {
int fd,len=1024*1024;
fd=open("hello",O_READ);
char*addr=mmap(0,len,PROT_READ+PROT_WRITE,MAP_SHARED,fd,0);
for(fd=0;fd<len;fd++)
putchar(addr[fd]);
if (addr==MAP_FAILED) {perror("mmap"); exit(1);}
printf("mmap returned %p, which seems readable and writable\n",addr);
munmap(addr,len);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
但是我无法执行这个程序,我的代码有什么问题吗?
我已经下载了cppcheck工具并构建它.现在我正面临着找不到cppcheck命令的问题.有没有错误......告诉我步骤..
我在gcc编译器中尝试过如下:
> cd /home/tcsujth/Desktop/cppcheck-1.46.1/ > g++ -o cppcheck -Ilib cli/*.cpp lib/*.cpp > ./cppcheck SYNTAX---------- cppcheck: error: could not find or open any of the paths given. Segmentation fault (core dumped) > cppcheck --version cppcheck: Command not found.