我XMLHttpRequest在JavaScript中使用.但是,它给了我一个错误,我不知道我的问题是什么.
我必须解析XML文件并将其内容分配给网页 - 这是我的代码:
<script = "text/javascript">
window.onload = onPageLoad();
var questionNum = 0;
function onPageLoad(questionNum) {
var xmlhttp = new XMLHttpRequest();
xmlhttp.open("GET","quiz.xml");
try {
xmlhttp.send(null); // Here a xmlhttprequestexception number 101 is thrown
} catch(err) {
document.getElementById("body").innerHTML += "\nXMLHttprequest error: " + err.description; // This prints "XMLHttprequest error: undefined" in the body.
}
xmlDoc = xmlhttp.responseXML;
parser = new DOMParser(); // This code is untested as it does not run this far.
}
</script>
Run Code Online (Sandbox Code Playgroud)
我的XML文件位于同一目录中.
<question>
<query>what …Run Code Online (Sandbox Code Playgroud) 我习惯了更高级的语言(java,python等),这已经很明显了.我试图将用户输入的字符串传递给cin,即要打开的文件的名称.似乎有某种指针疯狂错误,我的代码将无法编译.我删除了一些代码以使其更清晰.
#include <iostream>
#include <fstream>
using namespace std;
string hash(string filename);
int main(){
cout << "Please input a file name to hash\n";
string filename;
cin >> filename;
cout <<hash(filename);
return 0;
}
string hash(string filename){
file.open(filename);
if(file.is_open()){
file.close();
}
return returnval;
}
Run Code Online (Sandbox Code Playgroud)
这是编译时错误.
<code>
$ g++ md5.cpp
md5.cpp: In function ‘std::string hash(std::string)’:
md5.cpp:22: error: no matching function for call to ‘std::basic_ifstream<char, std::char_traits<char> >::open(std::string&)’
/usr/include/c++/4.2.1/fstream:518: note: candidates are: void std::basic_ifstream<_CharT, _Traits>::open(const char*, std::_Ios_Openmode) [with _CharT = char, _Traits = std::char_traits<char>]
</code> …Run Code Online (Sandbox Code Playgroud) 我可以更改EFLAGS寄存器中的VM标志吗?如果是这样,怎么样?
请注意,我不能只使用pushf,操纵堆栈上的值,然后popf.根据英特尔手册:
第2卷,第4.3章PUSHF:
"将整个EFLAGS寄存器复制到堆栈时,不会复制VM和RF标志(位16和17);而是在存储在堆栈中的EFLAGS映像中清除这些标志的值."
第2卷,第4.3章POPF:
"在特权级别0(或实地址模式,相当于特权级别0)的受保护,兼容性或64位模式下运行时,EFLAGS寄存器中的所有非保留标志(RF1,VIP,VIF除外) ,VM可能会被修改.VIP,VIF和VM不受影响."
我正在运行python 2.7.3并做一些涉及os模块的基本内容.
import os
def main():
f= os.popen('cat > out', 'w',1)
os.write(f, 'hello pipe')
os.close(f)
main()
Run Code Online (Sandbox Code Playgroud)
根据我看到的例子,我希望代码可以工作,但是解释器给出了这个错误:
Traceback (most recent call last):
File "./test.py", line 11, in <module>
main()
File "./test.py", line 8, in main
os.write(f, 'hello pipe')
TypeError: an integer is required
Run Code Online (Sandbox Code Playgroud)
好的,关闭文档.帮助页面说:
write(...)
write(fd, string) -> byteswritten
Write a string to a file descriptor.
Run Code Online (Sandbox Code Playgroud)
fd似乎代表文件描述符.据推测,当你做类似的事情时,这就是你得到的:
file = open('test.py')
Run Code Online (Sandbox Code Playgroud)
毫不奇怪,在线文档说的完全一样.这里发生了什么?
我的印象是以下代码会打印出"hello world",但它根本不打印任何东西.为什么?使用g ++ 4.2.1和cl ++ 3.2编译.
void iterateBackwards(){
std::string hiThere = "dlrow olleh";
for ( int i = hiThere.length(); i == 0; i--) {
std::cout << hiThere[i];
}
}
Run Code Online (Sandbox Code Playgroud)