我无法弄清楚为什么这不起作用......
我在Linux工作
g ++什么都不做
gcc打印以下内容:
/tmp/ccyg7NDd.o: In function `main':
test.cc:(.text+0x14): undefined reference to `std::cout'
test.cc:(.text+0x19): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'
test.cc:(.text+0x21): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&)'
test.cc:(.text+0x29): undefined reference to `std::basic_ostream<char, std::char_traits<char> >::operator<<(std::basic_ostream<char, std::char_traits<char> >& (*)(std::basic_ostream<char, std::char_traits<char> >&))'
/tmp/ccyg7NDd.o: In function `__static_initialization_and_destruction_0(int, int)':
test.cc:(.text+0x51): undefined reference to `std::ios_base::Init::Init()'
test.cc:(.text+0x56): undefined reference to `std::ios_base::Init::~Init()'
/tmp/ccyg7NDd.o:(.eh_frame+0x12): undefined reference to `__gxx_personality_v0'
collect2: ld returned 1 exit status
Run Code Online (Sandbox Code Playgroud)
码:
#include<iostream> …Run Code Online (Sandbox Code Playgroud) 我收到以下类型的错误.我知道它与我不正确地访问内存有关,但我不知道如何.请帮我看看我哪里出错了.
*注意我已经简化了我的功能,并且变量正在做什么并不明显,我只需要知道我是如何错误地实现函数或者我在滥用内存访问的地方.
int my_function(char const *file_name, size_t max)
{
myStruct.pStore = fopen(file_name,"w+"); //pStore is a FILE*
myStruct.max = max;
// fill the with zeros ('0')
int numberOfZeros = max*SIZE;
char zeros[numberOfZeros];
int i=0;
while(i<numberOfZeros) // insert zero's
{
zeros[i]='0';
i++;
}
fwrite(zeros,sizeof(char),numberOfZeros,myStruct.pStore);
fclose(myStruct.pStore);
return EXIT_SUCCESS;
Run Code Online (Sandbox Code Playgroud)
给出的错误:
*** glibc detected *** /home/.../: double free or corruption (top): 0x0804c008 ***
======= Backtrace: =========
/lib/i386-linux-gnu/libc.so.6(+0x73e42)[0xb7e82e42]
/lib/i386-linux-gnu/libc.so.6(fclose+0x154)[0xb7e72384]
/home/2012/spatar/cs/specs/release[0x80486b0]
/home/2012/spatar/cs/specs/release[0x8048acd]
/home/2012/spatar/cs/specs/release[0x8048af0]
/lib/i386-linux-gnu/libc.so.6(__libc_start_main+0xf3)[0xb7e284d3]
/home/2012/spatar/cs/specs/release[0x80484e1]
======= Memory map: ========
08048000-0804a000 r-xp 00000000 00:3b 2331829 /home/2012/spatar/cs/Aspecs/release
0804a000-0804b000 r--p …Run Code Online (Sandbox Code Playgroud) 我试图使用扫描仪从键盘获取一个int,但我收到以下错误:
Exception in thread "main" java.util.NoSuchElementException
at java.util.Scanner.throwFor(Scanner.java:907)
at java.util.Scanner.next(Scanner.java:1530)
at java.util.Scanner.nextInt(Scanner.java:2160)
at java.util.Scanner.nextInt(Scanner.java:2119)
at TableReader.mainMenu(TableReader.java:122)
at TableReader.main(TableReader.java:76)
Run Code Online (Sandbox Code Playgroud)
这就是我所拥有的.它独立于我的其余程序,我不明白为什么这不起作用.如果有帮助的话,它会在while循环中调用的方法中声明.
// scan for selection
Scanner s = new Scanner(System.in);
int choice = s.nextInt(); // error occurs at this line
s.close();
Run Code Online (Sandbox Code Playgroud)
我介绍了调试器并将错误缩小到:
Java运行时环境检测到致命错误:在pc = 0xb6bdc8a8处为SIGSEGV(0xb),pid = 5587,tid = 1828186944
JRE版本:7.0_07-b30 Java VM:OpenJDK服务器VM(23.2-b09混合模式linux-x86)有问题的框架:V [libjvm.so + 0x4258a8] java_lang_String :: utf8_length(oopDesc*)+ 0x58
无法编写核心转储.核心转储已被禁用.要启用核心转储,请在再次启动Java之前尝试"ulimit -c unlimited"
我在他们的网站上关注IBM的例子:
(清单#5)http://www.ibm.com/developerworks/library/l-bash-parameters/index.html
#!/bin/bash
echo "OPTIND starts at $OPTIND"
while getopts ":pq:" optname
do
case "$optname" in
"p")
echo "Option $optname is specified"
;;
"q")
echo "Option $optname has value $OPTARG"
;;
"?")
echo "Unknown option $OPTARG"
;;
":")
echo "No argument value for option $OPTARG"
;;
*)
# Should not occur
echo "Unknown error while processing options"
;;
esac
echo "OPTIND is now $OPTIND"
done
Run Code Online (Sandbox Code Playgroud)
我想要的是有一个名字超过1个字母的选项.即-pppp和-qqqq而不是-p和-q.
我写了我的程序并实现-help给了我一个问题......
假设我有一个像这样的文件指针:
file_ptr = fopen(“test.txt”, “r+”);
Run Code Online (Sandbox Code Playgroud)
char当我在流中移动时,我想改变每个的ASCII值(我这样做是一个密码,所以如果有更好或更有效的方法来做到这一点,请告诉我).
我试图用一个while(!feof(file_ptr)) {}环带fgetc()和fputc,但file_ptr将指向下一个字符,所以我想知道如果有什么我可以做一点上向后一斑.
基本上,我想知道相当于的文件流:
char* blah="blah blah";
char* index=blah;
index++;/*how to navigate a file stream in this way*/
Run Code Online (Sandbox Code Playgroud) 我需要帮助搞清楚为什么我在这里遇到分段错误.我已经过去了,我认为我的指针做错了,但我可以搞清楚是什么.
我的计划:
#include <stdlib.h>
#include <stdio.h>
void encrypt(char* c);
//characters are shifted by 175
int main(){
char* a;
*a = 'a';
/*SEGMENTATION FAULT HERE!*/
encrypt(a);
printf("test:%c/n",*a);
return 0;
};
void encrypt(char* c){
char* result;
int i=(int)(*c);
i+=175;
if(i>255)
{
i-=256;
}
*c=(char)i;
};
Run Code Online (Sandbox Code Playgroud) 这是我的一段代码......
def contactMaster(data="",url= str(chosenMaster)+"todolist"):
print "url: "+url
Run Code Online (Sandbox Code Playgroud)
它只打印"todolist"而不是"http://www.mysite.com/blah/1234/todolist"
为什么不工作?
我在SML中列出了N个元素。
我想将函数应用于该列表中的每个元素,因此我使用map。
但是,我要应用的函数具有多个这样的参数:
foo a b (c, d)
Run Code Online (Sandbox Code Playgroud)
其中a是我从列表中使用的元素,而bc和d是每次都相同的预定义变量。
我这样声明我的功能:
fun foo2 = map foo aList b (c,d)
Run Code Online (Sandbox Code Playgroud)
但是我遇到了一个运算符和操作数错误,这是预料之中的,但我可以想到任何其他方法来执行此操作。
我在w3school的测试仪中输入了这个,我无法弄清楚如何垂直对齐文本.vertical-align:middle;没有帮助.
<!DOCTYPE html>
<html>
<head>
<style>
ul
{
list-style-type:none;
margin:0;
padding:0;
}
a
{
display:block;
width:100px;
height:30px;
margin:5px;
background-color:#66CC33;
text-decoration:none; color:#000;
text-align:center;
font-family:"Verdana",Times,serif;
vertical-align:middle;
}
</style>
</head>
<body>
<ul>
<li><a href="#home">Home</a></li>
<li><a href="#news">News</a></li>
<li><a href="#contact">Contact</a></li>
<li><a href="#about">About</a></li>
</ul>
</body>
</html>
Run Code Online (Sandbox Code Playgroud) 我试图弄清楚为什么在我的代码部分,this.sleep(5000)似乎在我的绘制函数之前被调用,因为它在睡眠完成之前不会被绘制到画布.任何有关为什么这不符合我想要的方式的见解?
睡眠功能:
sleep: function(milliseconds) {
setTimeout(function(){
var start = new Date().getTime();
while ((new Date().getTime() - start) < milliseconds){
// Do nothing
}
},0);
},
Run Code Online (Sandbox Code Playgroud)
码:
var g = new Graph(this.diagram);
g.DrawPolygons(ctx,"blue");
this.sleep(5000);
Run Code Online (Sandbox Code Playgroud)